日期:2014-05-20 浏览次数:20794 次
public void judgedScore(){ BufferedReader br = null; try{ System.out.println("请输入成绩,并回车:"); br = new BufferedReader(new InputStreamReader(System.in)); String line = br.readline(); //做非法字符的判断,不是数字的等,这里就判断null和空字符 if(line == null || "".equals(line.trim())){ System.out.println("你录入的是非法字符,继续Y,其它建退出!"); br = new BufferedReader(new InputStreamReader(System.in)); line = br.readline(); } if(!"y".equalsIgnoreCase(line)){ return; } int score = Integer.parseInt(line.trim()); if(score > 100 || score < 0){ System.out.println("录入的是不符合逻辑的数值,继续Y,其它建退出!"); br = new BufferedReader(new InputStreamReader(System.in)); line = br.readline(); } if(!"y".equalsIgnoreCase(line)){ return; } int flag = 0; if(score >= 90){ flag = 1; }else if(score >= 80){ flag = 2; }else if(score >= 70){ flag = 2; }else if(score >= 60){ flag = 3; }else { flag = 4; } switch(flag){ case 1: System.out.println("你的成绩登记是A"); break; case 2: System.out.println("你的成绩登记是B"); break; case 3: System.out.println("你的成绩登记是C"); break; case 4: System.out.println("你的成绩登记是D"); break; default: System.out.println("成绩无效!"); } System.out.println("是否继续录入?继续Y,其它建退出!"); br = new BufferedReader(new InputStreamReader(System.in)); line = br.readline(); if("y".equalsIgnoreCase(line)){ judgedScore(); } }catch(Exception e){ } }