教育路上
摘要:使用do{}while()循环一直判断用户的输入,直到用户输入5时判断结果为false就跳出循环。以下是我们为大家整理的,相信大家阅读完后肯定有了自己的选择吧。
2021-06-06 21:08刘永莘
import java.io.*; public class MenuDemo { public static void main(String args[])throws IOException { char choice,a,b;//定义字符变量 System.out.println("系统功能:"); System.out.println("1.查询成绩"); System.out.println("2.录入数据"); System.out.println("3.打印数据"); System.out.println("4.修改数据"); System.out.println("5.退出系统"); System.out.println("请选择1~5:"); do { choice=(char)System.in.read();//读取输入的数字 System.out.println("");// a=(char)System.in.read();//回车符,读取后舍去 b=(char)System.in.read();//换行符,读取后舍去 switch(choice)//判断读入的字符 { case '1': System.out.println("正在查询"); break; case '2': System.out.println("正在录入"); break; case '3': System.out.println("正在打印"); break; case '4': System.out.println("正在修改"); break; case '5': System.out.println("再见!"); break; default: System.out.println("非法!重新选择!"); break; } }while(choice!='5'); } }
访客的评论 2024/03/28 23:08
文中描述的是准确的吗,如何报名!