课后小程序
1.
1 //信1605-3班 20163429 刘瑞欣 2 package Yichang; 3 import java.util.*; 4 5 class AException extends Exception 6 { 7 String a; 8 AException() 9 { 10 a="输入有误"; 11 } 12 public String toString() 13 { 14 return a; 15 } 16 } 17 18 class Chengji 19 { 20 public static void main(String args[]) 21 { 22 while(1>0) 23 { 24 Scanner sc = new Scanner(System.in); 25 System.out.println("请输入考试成绩(0~100):"); 26 try 27 { 28 String s = sc.nextLine(); 29 getnum(s); 30 } 31 catch (AException e) 32 { 33 System.out.println(e.toString()); 34 } 35 } 36 } 37 38 private static void getnum(String s) throws AException 39 { 40 for (int i = s.length()-1; i >= 0;i--) 41 { 42 int chr = s.charAt(i); 43 if (chr < 48 || chr > 57) 44 { 45 46 throw new AException(); 47 48 } 49 } 50 double num = Double.parseDouble(s); 51 if (num < 0 || num> 100) 52 { 53 throw new AException(); 54 } 55 if (num>= 0 && num< 60) 56 { 57 System.out.print("不及格\n"); 58 } 59 else if (num >= 60 && num <= 70) 60 { 61 System.out.print("及格\n"); 62 } 63 else if (num>= 70 && num<= 80) 64 { 65 System.out.print("中\n"); 66 } 67 else if (num >= 80 && num <= 90) 68 { 69 System.out.print("良\n"); 70 } 71 else 72 { 73 System.out.print("优\n"); 74 } 75 } 76 }
3.
直接输入回车就崩溃了。其他都不会崩溃。