首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java相关 >

帮帮JAVA新手的小忙!多谢

2012-08-07 
帮帮JAVA新手的小忙!谢谢class Test {public static void main(String[] args) {Scanner sc new Scanner

帮帮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");} 

热点排行