Java basic Syntax (operator)

Source: Internet
Author: User
Tags bitwise operators logical operators

If the negative number is modulo, the modulus symbol can be ignored, such as: 5%-2 = 1

for/, Integer divide and decimal divide are distinguished, integers are divide, and integers are preserved to remove remainder

+ Besides the function of string addition, we can convert non-string into string

System.out.println ("5+5=" +5+5);    5+5=55
System.out.println (' * ' + ' \ t ' + ' * ');  93SYSTEM.OUT.PRINTLN ("*" + ' \ t ' + ' * ');  //* *

 Public classTestApp {@Test Public voidTest () {intI1 = 10, I2= 20; inti = i1++; System.out.print ("I=" +i);//i=10System.out.println ("i=" +i1);//i=11I= ++I1; System.out.print ("I=" +i);//i=12System.out.println ("i=" +i1);//i=12I= i2--; System.out.print ("I=" +i);//i=20System.out.println ("i=" +i2);//i=19I= --I2; System.out.print ("I=" +i);//i=18System.out.println ("i=" +i2);//i=18    }}                

Assignment operators:

You can use automatic types for type conversions when data on both sides is inconsistent

  public  class   TestApp {@Test  public  void   Test () { boolean  B1 = false  ;  //  if  (B1 = true  " System.out.println ( "The result is true"  else   System.out.println ( "Result false"    
 Public class TestApp {    @Test    publicvoid  Test () {        int i = 1;        *= 0.1;        System.out.println (i); // 0        i++;        System.out.println (i); // 1     }}

Comparison operators

logical operators

An expression that is used by logical operators to concatenate Boolean types

The difference between & and &&:

&, whether true or false, both sides are to be operated on.

&&, the left is false, not the operation on the right

^ (XOR) and (|) Differences: When both sides are true, the result is false

@Test Public voidTest () {intx = 1; intY=1; if(X++==2 & ++y==2) {x=7; } System.out.println ("X=" +x+ ", y=" +y);//x=2,y=2x= 1; Y= 1; if(x++==2 && ++y==2) {x=7; } System.out.println ("X=" +x+ ", y=" +y);//X=2,y=1x= 1; Y= 1; if(X++==1 | ++y==1) {x=7; } System.out.println ("X=" +x+ ", y=" +y);//x=7,y=2x= 1; Y= 1; if(X++==1 | | ++y==1) {x=7; } System.out.println ("X=" +x+ ", y=" +y);//X=7,y=1}

  

Bitwise operators

Java basic Syntax (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.