日期:2014-05-20  浏览次数:20723 次

帮帮JAVA新手的小忙!谢谢
class Test {
  public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
  boolean flag = true;
  while (flag) {
  System.out.println("请输入1-100以内的数字");

  try {
  int score = sc.nextInt();
  if (score <= 100 && score >= 1) {
  System.out.println((char) ('E' - ((score - 1)) / 20));
  } else {
  System.out.println("您输入的数字超过范围");
  }
  } catch (Exception e) {
  System.out.println("您输入的数字不符合要求");
  }
  sc.nextLine();
  System.out.println("是否继续y/n");
  String s = sc.next();
  if (s.equals("y")){
  flag = true;
  }
  else if(s.equals("n")){
  System.out.println("谢谢使用再见");
  break;
  }
  }
  }
}

这个代码中System.out.println((char) ('E' - ((score - 1)) / 20));是什么意思啊?
还有这个catch (Exception e)什么意思啊?
  sc.nextLine();
这个next后面接Line是不是表示下行输入,next后面接Int是表示?

------解决方案--------------------
好像是俺写的。。。。

(char) ('E' - ((score - 1)) / 20)
这句话的意思就是
Java code
if (a >= 1 && a <= 20) {
                    System.out.println("E");
                } else if (a >= 21 && a <= 40) {
                    System.out.println("D");
                } else if (a >= 41 && a <= 60) {
                    System.out.println("C");
                } else if (a >= 61 && a <= 80) {
                    System.out.println("B");
                } else if (a >= 81 && a <= 100) {
                    System.out.println("A");
}