Source: http://www.imooc.com/code/1299
The comparison operator is used to determine the size of two data, for example: greater than, equal to, not equal to. The result of the comparison is a Boolean value (True or false).
The common comparison operators in Java are shown in the following table:
Attention, OH:
1, >, <, >=, <= only support the left and right sides of the operand is a numeric type
2, = =,! = The operands on either side of the number can be numeric types, or they can be reference types
Task
Verify your study results!
Add the correct comparison operators in the editor, 7, 8, 9, and then to achieve the following results:
1 Public classhelloworld{2 Public Static voidMain (string[] args) {3 intA=16;4 Doubleb=9.5;5String str1= "Hello";6String str2= "Imooc";7System.out.println ("A equals B:" +(a B));8SYSTEM.OUT.PRINTLN ("A greater than B:" +(a B));9System.out.println ("A is less than or equal to B:" +(a B));TenSystem.out.println ("str1 equals str2:" +(str1 str2)); One } A}
1 Public classhelloworld{2 Public Static voidMain (string[] args) {3 intA=16;4 Doubleb=9.5;5String str1= "Hello";6String str2= "Imooc";7System.out.println ("A equals B:" + (A = =b));8System.out.println ("A is greater than B:" + (a >=b));9System.out.println ("A is less than or equal to B:" + (a <=b));TenSystem.out.println ("str1 equals str2:" + (str1 = =str2)); One } A}
Web-Android Engineer first form comparison operator in -3-4 Java