1 classdemo03{2 Public Static voidMain (string[] args) {3 //relational operator = =4 5 //Example 16 intA = 10;7 intb = 10;8 Doublec = 10.0;9System.out.println (a==b);TenSystem.out.println (a==c); One //result True,true A /* - = = left, same type on right, direct comparison - = = left, the right type is inconsistent, first the value of a is promoted from the int type to the double type, and then the comparison the */ - - - //Example 2 + //decimal Question -System.out.println (3.0*10 = = 30.0); +System.out.println (3.14*10 = = 31.4); ASystem.out.println (3.141*10 = = 31.41); atSystem.out.println (3.1415*10 = = 31.415); - //result True,false,true,false - /* - questions about binary - 0.5 can be accurately expressed, 0.4 cannot be accurately represented - 0.5 in 0.25 - 0.125 1/8 to 0.0625 1/16 + 0.4 = 0.25 + 0.125 + ... - System.out.println (2.0-1.1); the in the actual development, when encountering the decimal problem, please use the BigDecimal class to handle. * $ Panax Notoginseng */ - the + //Example 3 AInteger i1= 1; theInteger i2= 1; +Integer i3= 127; -Integer i4= 127; $Integer i5= 128; $Integer i6= 128; -System.out.println (I1 = =i2); -System.out.println (i3 = =I4); theSYSTEM.OUT.PRINTLN (i5 = =I6); - //result True,true,falseWuyi //range of byte: -128~127 the - Wu //Example 4 - byteB1 = 1; AboutB1 = B1 + 1;//The result of the byte+int is the int type, the result is the loss accuracy, error $ } -}
Java interview (3)--Java relational operator