当前位置: 代码迷 >> Java相关 >> 帮帮JAVA新手的小忙!多谢
  详细解决方案

帮帮JAVA新手的小忙!多谢

热度:1242   发布时间:2013-02-25 21:45:12.0
帮帮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");}
  相关解决方案