Java Learning Note 2

Source: Internet
Author: User
Tags arithmetic operators logical operators

The five-spoke operator


Arithmetic operators

+ Plus

-Minus

* Multiply

/except

% take-up (modulo) (the remainder depends on the positive or negative of the molecule)


arithmetic operator int x1 = 10;int Y1 = 3; System.out.println (x1/y1);//The result is an integer//cast result of a double type of System.out.println (x1/(double) y1);// The remainder (the positive and negative depends on the positive or negative of the molecule) System.out.println (x1%y1); System.out.println (-X1%Y1); System.out.println (-X1%-Y1);


Self-increment auto-decrement operator

++n first operation, then value

n++ first value, then arithmetic

N=n+1


--n first operation, then value

n--first value, then arithmetic

N=n-1


Self-increment System.out.println (x1++),//First output 10, then ++system.out.println (++x1),//First + +, then output 12system.out.println (--X1);//First--, Re-output 11system.out.println (x1--),//First output 11, then--system.out.println (x1);//Output 10


Relational operators

> Greater than

< less than

>= greater than or equal to

<= less than or equal to

= = equals

! = does not equal


logical operators

&& and

|| Or

! Non -

Expression 1| | Expression 2, if expression 1 is true, the expression 2 does not need to be judged. If the expression 1 is false, you need to determine the expression 2.


if (++x1 > | | y1--< 3) {System.out.println ("x=" +x1+ ", y=" +y1);}


Difficulty bit operator

& After bitwise and conversion to binary, two number of the same column is 1 o'clock, 1; otherwise 0

| After a bitwise or conversion to binary, the two-digit same column is 0 o'clock, 0; otherwise 1

~ After bitwise inversion to binary, 0 is converted to 1, 1 is converted to 0

^ After bitwise XOR or conversion to binary, two numbers are the same as the same column, 0; not 1

>> right shift equals except 2

<< left shift equals multiply by 2

Note: The highest bit of the computer is displayed as a sign bit, 0 is positive, and 1 is negative

Negative complement = anti-code +1

Anti-code = In addition to the sign bit, you take the counter

The bitwise operator int x2 = 10;int y2 = 7;int Z2 = x2&y2;//is converted to binary, the two-digit same column is 1 o'clock, 1; otherwise 0system.out.println (z2); int z3 = z2|y2; System.out.println (Z3);//After conversion to binary, the two-digit same column is 0 o'clock, which is 0; otherwise 1int z4 = Z2^y2; System.out.println (Z4);//Convert to binary, two number same column, 0; not 1int z5 = ~x2; System.out.println (Z5);//convert to binary, 0 to 1, 1 to 0, negative complement = anti-code +1, anti-code = except for the sign bit, you take the inverse int z6 = x2>>2; System.out.println (z6); int z7 = x2<<2; System.out.println (Z7);


Assignment operators

variable = expression

VI. SELECT statement structure


Java Learning Note 2

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.