问题:根据读入的学生成绩,划分等级!
代码:
1.if-else:
package day; import java.util.Scanner; public class Day0204 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); for(int k = 0 ; k < 5 ; k++) { System.out.println("please input student score number:"); int score = sc.nextInt(); if(score <= 100) { if(score > 90) { System.out.println("优秀!"); }else if(score >= 80){ System.out.println("良好!"); }else if(score >= 70) { System.out.println("中等!"); }else if(score >= 60) { System.out.println("及格!"); }else if(score > 0) { System.out.println("不及格!"); }else { System.out.println("请正确输入成绩!"); } }else { System.out.println("请正确输入成绩!"); } } } }
2.Switch方法:
package day; import java.util.Scanner; public class Day0205 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); for(int k = 0 ; k < 5 ; k++) { System.out.println("please input number:"); int score = sc.nextInt(); switch(score/10) { case 10: System.out.print("优秀!"); break; case 9: System.out.println("优秀!"); break; case 8: System.out.println("良好!"); break; case 7: System.out.println("中等!"); break; case 6: System.out.println("及格!"); break; default: System.out.println("不及格!"); break; } } } }
还有什么好的方法或者代码有什么问题,请在评论区留言,大家一起学习进步哦!