任务二、评定成绩等级
一、采用并列式多分支结构评定成绩等级
public class Task01_01 {
public static void main(String[] args) {
// 声明部分
int score;
String level;
Scanner sc = new Scanner(System.in);
// 输入部分
System.out.print("score = ");
score = sc.nextInt();
// 处理部分
level = "";
if (score > 100) level = "超出范围";
if (score >= 90 && score <= 100) level = "优秀";
if (score >= 80 && score < 90) level = "良好";
if (score >= 70 && score < 80) level = "中等";
if (score >= 60 && score < 70) level = "及格";
if (score >= 0 && score < 60) level = "不及格";
if (score < 0) level = "超出范围";
// 输出部分
System.out.println(level);
}
}
二、采用并列式多分支结构评定成绩等级_升级版
public class Task01_01_ {
public static void main(String[] args) {
// 声明部分
int score;
String level;
Scanner sc = new Scanner(System.in);
// 输入部分
System.out.print("score = ");
score = sc.nextInt();
// 处理部分
level = "";
if (score < 0 || score > 100) level = "超出范围";
if (score >= 90 && score <= 100) level = "优秀";
if (score >= 80 && score < 90) level = "良好";
if (score >= 70 && score < 80) level = "中等";
if (score >= 60 && score < 70) level = "及格";
if (score >= 0 && score < 60) level = "不及格";
// 输出部分
System.out.println(level);
}
}
三、采用嵌套式多分支结构评定成绩等级
public class Task01_02 {
public static void main(String[] args) {
// 声明部分
int score;
String level;
Scanner sc = new Scanner(System.in);
// 输入部分
System.out.print("score = ");
score = sc.nextInt();
// 处理部分
level = "";
if (score > 100) {
level = "超出范围";
} else {
if (score >= 90) {
level = "优秀";
} else {
if (score >= 80) {
level = "良好";
} else {
if (score >= 70) {
level = "中等";
} else {
if (score >= 60) {
level = "及格";
} else {
if (score >= 0) {
level = "不及格";
} else {
level = "超出范围";
}
}
}
}
}
}
// 输出部分
System.out.println(level);
}
}
四、采用延拓式多分枝结构评定成绩等级
public class Task01_03 {
public static void main(String[] args) {
// 声明部分
int score;
String level;
Scanner sc = new Scanner(System.in);
// 输入部分
System.out.print("score = ");
score = sc.nextInt();
// 处理部分
level = "";
if (score > 100) {
level = "超出范围";
} else if (score >= 90) {
level = "优秀";
} else if (score >= 80) {
level = "良好";
} else if (score >= 70) {
level = "中等";
} else if (score >= 60) {
level = "及格";
} else if (score >= 0) {
level = "不及格";
} else {
level = "超出范围";
}
// 输出部分
System.out.println(level);
}
}
五、采用延拓式多分枝结构评定成绩等级升级版
public class Task01_03_ {
public static void main(String[] args) {
// 声明部分
int score;
String level;
Scanner sc = new Scanner(System.in);
// 输入部分
System.out.print("score = ");
score = sc.nextInt();
// 处理部分
level = "";
if (score < 0) {
level = "超出范围";
} else if (score < 60) {
level = "不及格";
} else if (score < 70) {
level = "及格";
} else if (score < 80) {
level = "中等";
} else if (score < 90) {
level = "良好";
} else if (score <= 100) {
level = "优秀";
} else {
level = "超出范围";
}
// 输出部分
System.out.println(level);
}
}
六、采用开关式多分枝结构评定成绩等级
public class Task01_04 {
public static void main(String[] args) {
// 声明部分
int score;
String level;
Scanner sc = new Scanner(System.in);
// 输入部分
System.out.print("score = ");
score = sc.nextInt();
// 处理部分
level = "";
if (score < 0 || score > 100) {
level = "超出范围";
} else {
switch (score / 10) {
case 10:
case 9:
level = "优秀";
break;
case 8:
level = "良好";
break;
case 7:
level = "中等";
break;
case 6:
level = "及格";
break;
default:
level = "不及格";
}
}
// 输出部分
System.out.println(level);
}
}