Java Operators
- Arithmetic Operators
- Relational Operators
- Bitwise Operators
Arithmetic Operators
Suppose int a = 5; int b = 10
Operators | Description Comments | Examples |
---|---|---|
+ | Symbol values are added on both sides | a + b is 15 |
- | Symbol subtracted from both sides | ba value 5 |
* | Symbol value multiplied sides | a * b value of 50 |
/ | Symbol sides divided value | b / a value of 2 |
% | Remainder | b% a remainder of 1 |
++ | Increment: Increase 1 | a ++ is 6 |
- - | Decrement: 1 reduction | b- - the value 9 |
Exercise : Arithmetic operators
- Consideration about: a ++ and ++ a What is the difference;
public class selfAddMinus { public static void main ( String [] args ) { int A = . 3 ; // define a variable; int B = ++ A ; // increment operator int C = . 3 ; int D = - C ; // decrement the System . OUT . the println ( "self-increase operation is equal to a value obtained by" + B ); the System . OUT. The println ( "self-subtraction value is equal to the" + D ); } }
Results:
1 first symbol, the first calculation, and then the results.
2. After the symbols, the first result, and then calculates.
Relational Operators
The 样 a = 5, b = 10;
Operators | Description Comments | Examples |
---|---|---|
== | Both values are equal, are equal is true | (a==b)false |
!= | Values on both sides are not equal, if not equal to true | (a!=b)true |
> | Left greater than right to true and false otherwise | (a> b)false |
< | Less than left to right the result is true or false | (a< b)true |
>= | Whether the left right is greater than or the like, for the establishment of true | (a>=b)false |
<= | The left side is less than or equal to the right, the establishment is true | (a<=b)true |
Exercise : Relational Operators
Bitwise Operators
=. 5 A, B = 10
the Java defines a bitwise operators, applied int, long, short, char, and other types of byte
Operators | Description Comments | Examples |
---|---|---|
& | If you are a position corresponding to 1, the result is 1, 0 otherwise | a & b the result is 0, i.e., 0000 0000 |
| | Corresponding bits are 0, the result is zero, otherwise 1 | a | result, namely 15 1111 |
^ | If the bit corresponding to the same value, the result is 0, otherwise 1 | a ^ b was 15 i.e. 1111 |
~ | Bitwise, i.e. becomes 0 becomes 0 1,1 | ~ A value |
<< | Remainder | b% a remainder of 1 |
>> | Increment: Increase 1 | a ++ is 6 |
>>> | Decrement: 1 reduction | b- - the value 9 |