编写一段程序,运行时向用户提问“你考了多少分?(0~100)”,接受输入后判断其等级并显示出来。
判断依据如下:
等级={优(90100 分);良(8089 分);中(6069 分);差(059 分);}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("你考了多少分?(0~100)");
int score = scanner.nextInt();
String level;
if (score >= 90 && score <= 100) {
level = "优";
} else if (score >= 80 && score <= 89) {
level = "良";
} else if (score >= 60 && score <= 69) {
level = "中";
} else if (score >= 0 && score <= 59) {
level = "差";
} else {
level = "输入有误";
}
System.out.println("你的等级是:" + level);
}
import java.util.Scanner;
public class GradeJudgment {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("你考了多少分?(0~100)");
int score = input.nextInt();
if (score >= 90 && score <= 100) {
System.out.println("你的等级是优。");
} else if (score >= 80 && score <= 89) {
System.out.println("你的等级是良。");
} else if (score >= 60 && score <= 69) {
System.out.println("你的等级是中。");
} else if (score >= 0 && score <= 59) {
System.out.println("你的等级是差。");
} else {
System.out.println("输入的分数不合法。");
}
}
}
不知道你这个问题是否已经解决, 如果还没有解决的话:import java.util.Scanner;
public class YourGrade {
public static void main (String[] args) {
YourGrade score = new YourGrade();
score.getGrade();
}
void getGrade() {
System.out.print("請輸入您的成績:");
Scanner input = new Scanner(System.in);
int your_score = input.nextInt();
if (your_score>=90 && your_score<=100) {
System.out.println("您的成績為:優秀!\n");
System.out.println("昔時賢文,誨汝諄諄。");
}
else if (your_score>=80 && your_score<=89) {
System.out.println("您的成績為:良好!\n");
System.out.println("集韻增廣,多見多聞。");
}
else if (your_score>=70 && your_score<=79) {
System.out.println("您的成績為:中等!\n");
System.out.println("觀今宜鑒古,無古不成今。");
}
else if (your_score>=60 && your_score<=69) {
System.out.println("您的成績為:及格!\n");
System.out.println("知己知彼,將心比心。");
}
else {
System.out.println("您的成績為:不及格!\n");
System.out.println("酒逢知己飲,詩向會人吟。");
}
}
}