Operators and Expressions
Operators are like tools that let you manipulate data. They are the building blocks of expressions. Java provides several categories of operators.
Arithmetic Operators
+ - * / %int a = 10, b = 3;
System.out.println(a + b); // 13
System.out.println(a - b); // 7
System.out.println(a * b); // 30
System.out.println(a / b); // 3 (integer division)
System.out.println(a % b); // 1
Relational Operators
== != > < >= <=Logical Operators
&& || !Assignment Operators
= += -= *= /= %=int x = 5;
x += 3; // x = x + 3
Increment/Decrement
++ -- (prefix and postfix)int count = 0;
System.out.println(count++); // prints 0, then count becomes 1
System.out.println(++count); // count becomes 2, then prints 2
Two Minute Drill
- Arithmetic operators: +, -, *, /, %
- Relational operators: ==, !=, <, >, <=, >=
- Logical operators: &&, ||, !
- Assignment shortcuts: +=, -=, etc.
- Increment/Decrement: ++, -- with prefix/postfix difference.
Need more clarification?
Drop us an email at career@quipoinfotech.com
