Java interview (3)--Java relational operator

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.