Arithmetic operators Symbol Name Example Addition cab Subtraction
Arithmetic operators Symbol Name Example + Addition c=a+b - Subtraction c=a-b * Multiplication c=a*b / Division c=a/b % Modulo c=a%b
int a = 5; int b = 3; System. out. println(a + " + b + " = " + (a + b)); System. out. println(a + " - " + b + " = " + (a - b)); System. out. println(a + " * " + b + " = " + (a * b)); System. out. println(a + " / " + b + " = " + (a / b)); System. out. println(a + " % " + b + " = " + (a % b));
Compound assignment Operator += -= *= /= %= >>= <<= &= ^= |= a a a a a Example += 2; -= 2; *= 2; /= 2; %= 2; >>= 2; <<= 2 & = 2; ^= 2; |= 2; Equivalent to a=a+2 a=a-2 a=a*2 a= a / 2 a=a%2 a = a >> 2 a = a << 2 a=a&2 a= a ^ 2 a=a|2
Increment and decrement Operator ++ (prefix) ++ (posfix) -- (prefix) -- (postfix) Example ++a; a++; --a; a--; a a Equivalent to = a + 1; = a - 1;
Relational and comparison operators Operat Examp Result er le == a == b true if `a` equal to `b`, otherwise false != a != b true if `a` not equal to `b`, otherwise false < a<b true if `a` less than `b`, otherwise false > a>b true if `a` greater than `b`, otherwise false <= a <= b true if `a` less than or equal to `b`, otherwise false >= a >= b true if `a` greater than or equal to `b`, otherwise false
Logical operators ! && || Operator Not And Or Name Example ! true && true || false
Bitwise operators & | ^ ~ << >> Symbol Description Bitwise AND Bitwise inclusive OR Bitwise exclusive OR bit inversion Shift bits left Shift bits right
- Slides: 10