第十六讲——IF的选择结构
第十六讲——IF的选择结构与&&(连接符)
一共三种
- if()==true{} //如果真则
- if()==true{}else{} //如果真则 否则
- if()==true{}else if {}else if {}else if {}....else{} //如果真则 否则 否则 否则 ...(最后一定要else结尾)
Demo01—IF单选择结构
如果满足则,,不满足跳过
test01
package scanner;
import java.util.Scanner;
public class Demo04 {
public static void main(String[]ages){
Scanner scanner = new Scanner(System.in);
if(1==1){
System.out.println("true");
}
}
}
显示 (如果条件不满足即不等于就啥也不显示跳过)
C:\Users\夏天的风\Desktop\DEMO-XXZ\out\production\DEMO-XXZ scanner.Demo04
true
Process finished with exit code 0
Demo02—IF双选择结构
如果满足则,,否则,,,
test01
package scanner;
import java.util.Scanner;
public class Demo04 {
public static void main(String[]ages){
Scanner scanner = new Scanner(System.in);
if(1==2){
System.out.println("true");
} else {
System.out.println("false");
}
}
}
C:\Users\夏天的风\Desktop\DEMO-XXZ\out\production\DEMO-XXZ scanner.Demo04
false
Process finished with exit code 0
Demo03—IF多选择结构
如果满足则,,否则,,,否则,,,否则,,,否则,,,
test
package scanner;
import java.util.Scanner;
public class Demo04 {
public static void main(String[]ages){
Scanner scanner = new Scanner(System.in);
int score = scanner.nextInt();
if(score==100){
System.out.println("你Tm天才 !!!满分!!");
}else if(score>=90){
System.out.println("厉害 优秀!!!");
}else if(score>=80){
System.out.println("良好!!! 继续努力!!!");
}else if(score>=60){
System.out.println("合格 请继续加油ao~");
}else {
System.out.println("不合格:(");
}
}
}
显示
C:\Users\夏天的风\Desktop\DEMO-XXZ\out\production\DEMO-XXZ scanner.Demo04
85
良好!!! 继续努力!!!
Process finished with exit code 0
连接符(&&);
并的意思
格式
else if(A>10 && A<20){ ,,,,,,, } // 10<A<20
如果你有梦想 就努力去实现 就这样