Day20210204
选择结构:
if单选择结构
if双选择结构
if多选择结构
嵌套的if结构
switch多选择结构
if双选择结构语法:if(布尔表达式){如果布尔表达式的值为true} else{如果布尔表达式的值为false}
package com.icebear.struct;
import java.util.Scanner;
public class ifSwitchStruct03 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
/*
if 语句中至多有一个else语句,else语句在所有else if语句之后。
if语句中可以有若干个elseif语句,它们必须在else语句之前。
一旦其中一个else if语句检测为true,其他的else if以及else语句都将跳过执行
*/
System.out.println("请输入成绩");
double Score = scanner.nextDouble();
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("及格");}
else if (Score<60&&Score>=0){
System.out.println("不及格");}
else {
System.out.println("成绩不合法");}
scanner.close();
}
}
浙公网安备 33010602011771号