...从键盘输入学生成绩,根据成绩判断:如果成绩小于60,则输出“不及格...
发布网友
发布时间:2024-10-20 18:18
我来回答
共3个回答
热心网友
时间:2024-12-01 01:24
public static void main(String[] args) throws Exception {
System.out.print("请输入成绩:");
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
try {
int score = Integer.parseInt(str);
if (score >= 0 && score < 60){
System.out.println("不及格");
} else if (score >= 60 && score < 75){
System.out.println("及格");
} else if (score >= 75 && score < 90) {
System.out.println("良");
} else if (score >= 90 && score <= 100){
System.out.println("优");
} else {
System.out.println("成绩无效");
}
} catch (NumberFormatException e){
System.out.println("成绩输入错误");
}
}
代码还是自己敲的好
热心网友
时间:2024-12-01 01:22
public static void main(String[] args) throws Exception {
System.out.print("请输入成绩:");
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
try {
int score = Integer.parseInt(str);
if (score >= 0 && score < 60){
System.out.println("不及格");
} else if (score >= 60 && score < 75){
System.out.println("及格");
} else if (score >= 75 && score < 90) {
System.out.println("良");
} else if (score >= 90 && score <= 100){
System.out.println("优");
} else {
System.out.println("成绩无效");
}
} catch (NumberFormatException e){
System.out.println("成绩输入错误");
}
}
热心网友
时间:2024-12-01 01:23
import java.util.Scanner;
public class ScoreJudge {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double score = 0;
try {
System.out.print("请输入成绩:");
score = sc.nextDouble();
} catch (NumberFormatException nbFmtExp) {
System.out.println("成绩输入错误");
return;
}
if (score < 0 || score > 100) {
System.out.println("成绩无效");
}
if (score >= 0) {
if (score < 60) {
System.out.println("不及格");
} else if (score < 75) {
System.out.println("及格");
} else if (score < 90) {
System.out.println("良");
} else if (score <= 100) {
System.out.println("优");
}
}
}
}