Common logical operators
|
Operator |
Chinese name |
An expression |
Description |
Example |
|
&& |
And, and |
Condition 1&& Condition 2 |
Two conditions are true at the same time, the result is true; two conditions have one false, then the result is false |
With the right to vote: At least 18 years of age && Chinese citizens. Two of the conditions are true and have the right to vote. One condition is false, then there is no right to vote. |
|
|| |
Or, or |
Condition 1| | Condition 2 |
Two conditions have one true, then the result is true; two conditions are false at the same time, the result is false |
How to go to America from China: by plane | | Boat. Two conditions if one condition is true, you can go to the United States. If all is false, then can not go to the United States |
|
! |
Non - |
! Conditions |
If the condition is true, the result is false; when the condition is false, the result is true |
The condition of becoming a good software engineer:! Lazy |
The method for generating a random number (any integer in 0~9) is as follows.
int random= (int) (Math.random () *10); Generate random numbers
Determines whether an integer
Boolean flag=input.hasnextint ();
S1/using Java to understand program logic/03-selection Structure (i)