Java know how many (12) operators

Source: Internet
Author: User

The operators in Java are almost the same as C + +. Mathematical operator mathematical operation, the result is a numeric value. See table below:
operator Description Example
+ Addition 1 + 2
- Subtraction 4-3.4
* Multiplication 7 * 1.5
/ Division 3.5/7
% Take surplus 7% 2
++ Self-increment 3++
-- Self-reduction 3--
Relational operator relational operator with the result of a Boolean value. See table below:
operator Description Example
> Greater than A > 4.2
>= Greater than or equal 3.4 >= B
< Less than 1.5 < 9
<= Less than or equal 6 <= 1
== Equals 2 = = 2
!= Not equal to 2! = 2
&& And True && false
|| Or (3 > 1) | | (2 = = 1)
! Non - !true
The bitwise operator bitwise operator makes a bitwise logical operation on the binary form of an integer, resulting in an integer. See table below:
operator Description Example
& And 1 & 4
| Or 2 | 5
^ XOR or 2 ^ 3
~ Non - -
<< Move left 5 << 3
>> Move right 6 >> 1
Conditional operators also have a conditional operator (trinocular operator) in Java:
Condition? X1:x2
Condition is a Boolean value. According to condition, take the value of X1 or X2.

Here is a comprehensive example of an operator:
1  Public classDemo {2  Public Static voidMain (string[] args) {3       inta=10;4 intb=10;5       intx=10;6 intY=21;7       intz=10;8System.out.println ("Post-add a=" + (a++));9System.out.println ("A's value a=" +a);TenSystem.out.println ("Pre-add b=" + (+ +)b)); OneSystem.out.println ("---------------------"); ASystem.out.println ("Say X>y, right?") "+ (x>y)); -System.out.println ("Think X>y and X<y, right?" "+ ((x>y) && (x<( y) )); -System.out.println ("Think x>=y or x==y, right?") "+ ((x>=y) | | (x==( y) )); theSystem.out.println ("Think X<y or x=z, right?") "+ ((x<y) | | (x==( z) )); -System.out.println ("---------------------"); -System.out.println ("A&x The result is:" + (a&x)); -System.out.println ("A|x The result is:" + (a|x)); +System.out.println ("Y^z The result is:" + (y^z)); -System.out.println ("---------------------"); +System.out.println ("A left 2-bit result is:" + (a<<2)); ASystem.out.println ("Y-shift 3-bit result is:" + (y>>3)); at } -}
Operation Result:
After self-add a=10
The value of a a=11
Former self-add b=11
---------------------
Say X>y, right? False
Think X>y and X<y, right? False
Think X>=y or x==y, right? False
Think X<y or x=z, right? True
---------------------
The result of the a&x is: 10
The result of the a|x is: 11
The result of the y^z is: 31
---------------------
A 2-bit left shift result is: 44
The result of the right shift of Y 3 bits is: 2

Series Articles:

Java know how much (1) Language overview

Java know how much (2) virtual machine (JVM) and cross-platform principle

Java know how much (3) employment direction

Java know how much (4) the difference between J2SE, Java EE, J2ME

Java know how much (5) Build Java development environment

Java know how much (6) The first example of a program

Java knows how many (7) classes and objects

Java know how much (8) class library and its organizational structure

Java know how much (9) Import and Java class search path

Java know how much (10) data types and variables

Java know how much (11) data type conversions

Java know how many (12) operators

Java know how many (12) operators

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.