java编程,用switch语句编写一个学生成绩等级评定,使用键盘读取分数(0-100之间)学生成

2024-11-21 05:10:17
推荐回答(5个)
回答1:


public class Grade {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int grade = scanner.nextInt();
        switch (grade/10){
            case 10:
            case 9:
                System.out.println("成绩:"+grade+"\t 等级 "+"A");
                break;
            case 8:
                System.out.println("成绩:"+grade+"\t 等级 "+"B");
                break;
            case 7:
                System.out.println("成绩:"+grade+"\t 等级 "+"C");
                break;
            case 6:
                System.out.println("成绩:"+grade+"\t 等级 "+"D");
                break;
            default:
                System.out.println("成绩:"+grade+"\t 等级 "+"E");
                break;
        }
    }
}

回答2:

import java.util.Scanner;
public class GetGrade {
public static void main(String[] args) {
System.out.println("请输入成绩(1-100)");
Scanner sc = new Scanner(System.in);
int score = sc.nextInt();
if (score < 0 || score > 100) {
System.out.println("对不起,你输入有误");
return;
}
System.out.println("你获得了:"+getGrade(score));
}
public static String getGrade(int i) {
String ret = null;
switch (i / 10) {
case 10:
ret = "A";
break;
case 9:
ret = "A";
break;
case 8:
ret = "B";
break;
case 7:
ret = "C";
break;
case 6:
ret = "D";
break;
default:
ret = "E";
break;
}
return ret;
}
}

回答3:

import java.util.Scanner;
public class fenshu {
public static void main(String[] args) {
//TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int mark=sc.nextInt();
switch(mark/10)
{

case 10:
case 9: System.out.print("A");break;
case 8: System.out.print("B");break;
case 7: System.out.print("C");break;
case 6: System.out.print("D");break;
default:System.out.print("E");
}

}
}

回答4:

public static void main(String[] args) {
Scanner sn = new Scanner(System.in);
System.out.print("请输入百分制的分数:");
while (sn.hasNext()) {
String scStr = sn.next();
int sc = 0;
try {
sc = Integer.valueOf(scStr);
} catch (Exception e) {
System.out.print("请输入百分制的分数:");
continue;
}
if (sc < 0 || sc > 100) {
System.out.print("请输入百分制的分数:");
continue;
}
int s = sc / 10;
switch (s) {
case 10:
case 9:
System.out.println("A");
break;
case 8:
System.out.println("B");
break;
case 7:
System.out.println("C");
break;
case 6:
System.out.println("D");
break;
default:
System.out.println("E");
break;
}
System.out.print("请输入百分制的分数:");
}
}

回答5:

这个是最最初级的东西,如果这个不会就没必要写开发了