Operator (1)

1, increment decrement
int. 3 = A;
int = A B ++; // after the implementation, b = 3. B give an assignment, and then increment.
System.out.println ( "a =" + a + "\ nb =" + b);

A =. 3 int;
int B = A ++; // after the implementation, b = 4. The first increment, after the assignment.
System.out.println ( "a =" + a + "\ nb =" + b);
decrement operations use the same increment
2, relational operators
is equal to: a == b;
is not equal to: a = b;!
Greater than: a> b;
less than: a <b;
less than or equal to: a <= b;
greater than or equal to: a> = b;
resultant only two true and false Boolean
3, logical operators: shipped Boolean operations value.
Logical AND: &, both operands are true, the result is true, otherwise it is false.
Logical OR: |, there is a two operands is true, the result is true.
Logical NOT:, negated!
Logical XOR: the same is false, different to true.
4, bitwise
negation: ~
bitwise AND: &
Bitwise OR: |
left shift operator: <<
right-shift operator: >>
public class Demo3 {
public static void main (String [] args) {
int A . 3 =;
int = B. 4;
System.out.println (A & B); // result is 0
System.out.println (a | b); // results. 7
System.out.println (A ^ B); // results. 7
System.out.println (~ A); // result is -4, trans code is negative -1

    //移位
    int c = 3<<2;
    System.out.println(c);  //结果为12
    System.out.println(6>>1);//结果为3
}

}

Guess you like

Origin www.cnblogs.com/ma1998/p/11432276.html
Recommended