Java programming those things 22-comparison operators Zhengzhou game college Chen yuefeng from: http://blog.csdn.net/mailbomb
4.2 comparison OperatorsComparison operators are used to compare the data sizes or equal values. The comparison operator returns a Boolean value. If the comparison result is true, the result is true. Otherwise, the result is false. For the Expression and Function of comparison operators in Java, see Table 4-2. Table 4-2 Comparison Operators
Symbol |
Name |
Function Description |
> |
Greater |
Compare whether the number on the left is greater than the number on the right |
< |
Less |
Compare whether the number on the left is smaller than the number on the right |
> = |
Greater than or equal |
Compare whether the left digit is greater than or equal to the right digit |
<= |
Less than or equal |
Compare whether the number on the left is less than or equal to the number on the right |
= |
Equal |
Compare whether the left digit is equal to the right digit |
! = |
Not equal |
Compare whether the left digit is not equal to the right digit |
The calculation rules of comparison operators are the same as those in reality. Note the following: The L boolean type can only be equal or not equal, but cannot be larger. L> = indicates that the value is greater than or equal to. Therefore, 5> = 5 is true. L The range [) expressed in mathematics, that is, the number is greater than or equal to 1 and less than 10. the following format cannot be written in the program: 1 <= n <10, this writing is syntactic incorrect. If you need to express this interval, see section 4.3 logical operator implementation. L be especially careful when determining whether equal symbols are two equal signs rather than one equal sign. The example code used for the comparison operation is as follows: int A = 10; Boolean B = (A> 3); // The condition is true, the value true is assigned to the variable B Boolean c = (B = true); // The condition is true and the result is true in the actual code, values, variables, and calculation results can be directly involved in the comparison, but in order to enhance readability in the program, sometimes the comparison needs to be written separately. Comparison operators are the basis for data comparison in programming and also the basis for many logical implementations. In program logic, we often compare certain conditions to determine how to execute subsequent programs.