java 设学生成绩在以下4个分数段,85~100为A,70~84为B,60~69为C,0~59为D,要求用switch语句编写程序。
展开全部
import java.util.Scanner;
public class Fenshu {
public static void main(String[] args) {
int s = 0,a=0;
System.out.println("请输入分数");
Scanner b=new Scanner(System.in);
s=b.nextInt();
if(s>=85&&s<=100){
a=1;
}else if(s>=70&&s<85){
a=2;
}else if(s>=60&&s<70){
a=3;
}else if(s>=0&&s<60){
a=4;
}else{
a=5;
}
switch(a){
case 1:
System.out.println("A");
break;
case 2:
System.out.println("B");
case 3:
System.out.println("C");
case 4:
System.out.println("D");
case 5:
System.out.println("输入错误");
}
}
}
public class Fenshu {
public static void main(String[] args) {
int s = 0,a=0;
System.out.println("请输入分数");
Scanner b=new Scanner(System.in);
s=b.nextInt();
if(s>=85&&s<=100){
a=1;
}else if(s>=70&&s<85){
a=2;
}else if(s>=60&&s<70){
a=3;
}else if(s>=0&&s<60){
a=4;
}else{
a=5;
}
switch(a){
case 1:
System.out.println("A");
break;
case 2:
System.out.println("B");
case 3:
System.out.println("C");
case 4:
System.out.println("D");
case 5:
System.out.println("输入错误");
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询