1 import java.util.InputMismatchException; 2 import java.util.Scanner; 3 4 /* 5 键盘录入学生的成绩,将100分划分四个等级,优.良.及.不及。输出对应的等级,要有容错处理 6 */ 7 public class Demo { 8 public static void main(String[] args){ 9 Scanner sc = new Scanner(System.in); 10 try { 11 while (true){ 12 System.out.println("请输入成绩:"); 13 int score = sc.nextInt(); 14 if (score < 0 || score >100){ 15 System.out.println("输入的成绩不符合题目的要求"); 16 continue; 17 } 18 if (score >= 90 && score <100){ 19 System.out.println("优秀"); 20 }else if (score >= 80 && score <90){ 21 System.out.println("良好"); 22 }else if (score >= 60 && score < 80){ 23 System.out.println("及格"); 24 }else { 25 System.out.println("不及格"); 26 } 27 } 28 }catch (InputMismatchException e){ 29 System.out.println("输入的不是整数"); 30 } 31 } 32 }
原文地址:https://www.cnblogs.com/wangjixue/p/12121478.html
时间: 2024-11-08 14:13:14