Public class ifonly {
Public static void main (string [] ARGs ){
Int income = 1100000;
If (income >= 1000000)
System. Out. println ("visiting Australia to see Koala ");
If (income >= 500000)
System. Out. println ("go to Sichuan to see pandatv ");
If (income <1, 500000)
System. Out. println ("go to the park to see Golden hound ");
}
}
Output: go to Australia to see koala
Go to Sichuan to see pandatv
Class ifelsestate {
Public static void main (string [] ARGs ){
Int income = 1100000; // assume the annual salary is 1.1 million
If (income >= 1000000 ){
System. Out. println ("visiting Australia to see Koala ");
}
Else if (income >= 500000 ){
System. Out. println ("go to Sichuan to see pandatv ");
}
Else {
System. Out. println ("go to the park to see Golden hound ");
}
}
}
Output: go to Australia to see koala
If you simply use if to compile the Statement, the concept is like "Multi-choice questions". That is to say, each if condition is independent. Even if the first if condition is true, then each condition is determined; not like if-else. As long as the first conditional is true, all subsequent conditional statements are not judged.