package text1;
import java.util.Scanner;
public class IfDemo02 {
public static void main(String[] args) {
// TODO 自动生成的方法存根
Scanner scanner = new Scanner(System.in);
System.out.println("请输入成绩");
int score = scanner.nextInt();
/* if 语句至多有一个else语句, else语句在所有的else if 语句之后
* if 语句里面可以有很多个else if语句
* 若if 语句不成立,则执行else if 语句,如果其中一个else if 检测为true,其他的else if 以及else语句都得跳过
*
*
*/
if(score==100) {
System.out.println("恭喜你,满分!");
}else if(score<100 && score>=90) {
System.out.println("获得A");
}else if(score<90 && score>=80) {
System.out.println("获得B");
}else if(score<80 && score>=70) {
System.out.println("获得C");
}else if(score<70 && score>=60) {
System.out.println("获得D");
}else if(score<60 && score>0) {
System.out.println("很遗憾,不及格,下次继续努力");
}else {
System.out.println("成绩不合法");
}
scanner.close();
}
}
if 多分支
于 2022-04-17 12:04:25 首次发布