Example of operators
int result = 1 + 2; // addition
result = result - 1; // subtraction
result = result * 10; // multiplication
result = result / 5; // division
result = result % 3; // modulus
Abbreviating of operators
// result = result + 1;
result++;
// result = result - 1;
result--;
// result = result + 2;
result += 2;
// result = result * 10;
result *= 10;
// result = result / 3;
result /= 3;
// result = result % 2;
result %= 2;
Arithmetic operators
+, -, *, /, %, ++, --
Assignment operators
=, +=, -=, *=, /=, %=, &=, |=, ^=, >>=, <<=
Comparison operators
==, !=, >, <, >=, <=
Logical operators
&&, ||, !
Bitwise operators
&, |, ~, ^, <<, >>, >>>
Another operator is Ternary Operator
boolean loggedIn = false;
String userStatus = loggedIn ? "User is loggedIn" : "User is not logged in";
System.out.println(userStatus);
More details can be found in
w3schools.com
oracle.com
Top comments (0)