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("成绩输入错误");
}
}
代码还是自己敲的好
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("成绩输入错误");
}
}
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("优");
}
}
}
}