&&需要用到這個運算符
public class HelloWorld {
? ? public static void main(String[] args) {
int age=25;
if(age > 60){
? ? System.out.println("老年");
}else if (age >40 && age < 60 ){
? ? System.out.println("中年");
}else if(age > 18&&age < 40 ){
? ? ?System.out.println("少年");
}else{
? ? ?System.out.println("童年");
}
2021-07-29
public class HelloWorld { public static void main(String[] args) {
int age=25;
If ( age >= 60){
System. out. printLn( “老年”) ;
} else if (40<= age <60){
System. out. printLn( “中年”) ;
} else if ( 18<= age<40) {
System. out. printLn( “ 少年”) ;
} else (0< age < 18){
System. out. printLn( “ 兒童”);
}
}
}
2021-07-29
public class HelloWorld { public static void main(String[] args) {
int age=25;
If ( age >= 60){
System. out. printLn( “老年”) ;
} else if (40<= age <60){
System. out. printLn( “中年”) ;
} else if ( 18<= age<40) {
System. out. printLn( “ 少年”) ;
} else (0< age < 18){
System. out. printLn( “ 兒童”)
}
}
}
2021-07-18
if(age > 60){
? ? ? ? System.out.println("老年");
? ? }else if(age >= 40){
? ? ? ? System.out.println("中年");
? ? }else if(age >= 18){
? ? ? ? System.out.println("少年");
? ? }else{
? ? ? ? System.out.println("童年");
? ? }
不需要使用&&,if-else語句是逐步判斷的,在 if(age > 60) 就已經(jīng)將age可能的值根據(jù)60劃為兩類