顺序结构
- Java的基本结构就是顺序结构,除非特别指明,否则就按照顺序一句句执行。
- 顺序结构是最基本的算法结构
IF选择结构
if单选择结构
if(true/*boolean*/){
//如果是true则执行程序
}
if双选择结构
if(true/*boolean*/){
//如果布尔表达式的值为true,则执行
}else{
//如果布尔表达式的值为false,则执行
}
if多选择结构
if(boolean1){
//boolean1为ture执行
}else if(boolean2){
//boolean2为ture执行
}else if (boolean3){
//boolean3为ture执行
}else{
//都不为ture则执行
}
多选择结构的最后一定要有单独的else
实例,通过输入分数进行成绩判断:
Scanner scanner = new Scanner(System.in);
//score 成绩
int score = scanner.nextInt();
if(score == 100){
System.out.println("你的分数为:" + score + "分,满分王者。");
}else if (score <100 && score >= 90){
System.out.println("你的分数为:" + score + "分,你获得了A。");
}else if (score <90&& score >= 80){
System.out.println("你的分数为:" + score + "分,你获得了B");
}else if (score <80 && score >= 70){
System.out.println("你的分数为:" + score + "分,你获得了C");
}else if (score <70 && score >= 60){
System.out.println("你的分数为:" + score + "分,你获得了D");
}else if(score <60 && score >= 0){
System.out.println("你的分数为:"