compareprimitive.java

来自「主要是对于JAVA的编程的基本语言 希望能够帮得上你。」· Java 代码 · 共 33 行

JAVA
33
字号
package Operator;

/*
 Equality for primitives 
 Most programmers are familiar with comparing primitive values. 
 The following code shows some primitives being compared for equality:
*/

class ComparePrimitives {
   public static void main(String [] args) {	  
      System.out.println("character 'a' == 'a'? " + ('a' == 'a'));
      System.out.println("character 'a' == 'b'? " + ('a' == 'b'));
      System.out.println("5 != 6? " + (5 != 6));
      System.out.println("5.0 == 5L? " + (5.0 == 5L));
      System.out.println("true == false? " + (true == false));
      System.out.println("true != false? " + (true != false));
   }
}

/*
 Notice that in line six we are comparing an integer to a float number. 
 This program produces the following output:
 
 character 'a' == 'a'? true
 character 'a' == 'b'? false
 5 != 6? true
 5.0 == 5L? true
 true == false? false
 
 As we can see, if a float is compared with an integer and
 the values are the same, the == operator returns true as expected. 
*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?