Java Operators
Java supports rich set of operators. we have already used several of them such as = , +, -, and * . an operator is a symbol that tells a computer to perform certain mathematical or logical manipulations. Operators are used in programs to manipulate data and variables. Java operators can be classified into
1. Arithmetic operators
2. Relational Operators
3. Logical Operators
4. Assignment Operators
5. Increment and Decrement operators
6. Conditional Operators
7. Bitwise operators
8. Special operators.
1. Arithmetic operators
Arithmetic operators are used in mathematical expressions in the same way that they are used in algebra. Java provides all the basic arithmetic operations.The following table lists the arithmetic operators:
- Addition (+)
- Subtraction (-)
- Multiplication (*)
- Division (/)
- Modulus (%)
program : 01
output:01
2. Relational Operators
- Equal to (= =)
- Not equal to (!=)
- Greater than (>)
- Less than (<)
- Greater than or equal to (>=)
- Less than or equal to (<=)
program : 02
output:02
3. Logical Operators
Java has three logical operators. The logical operators && and || are used when we want to form compound condition by combining two or more relations. An example is: a>b && x==10 An expression of this kind which combines two or more relational expressions is termed as logical expression or a compound relational expression. A logical expression also yields a value of true or false according to the truth table.
- Logical AND ( && )
- Logical OR ( || )
- Logical NOT ( ! )
Truth table
Op-1 Op-2 Op1&&op-2 Op-1||op2
True True True true
True False False true
False True False true
False False False false
program : 03
output:03
4. Assignment Operators
- Assignment (=)
- Compound Assignment Operators (e.g., +=, -=, *=, /=, %=)
program : 04
output:04
5. Increment and Decrement operators
- Increment (++)
- Decrement (--)
program : 05
output:05
6. Conditional Operators
- (condition) ? expression1 : expression2
program : 06
output:06
7. Bitwise operators
- Bitwise AND (&)
- Bitwise OR (|)
- Bitwise XOR (^)
- Bitwise NOT (~)
- Left Shift (<<)
- Right Shift (>>)
- Unsigned Right Shift (>>>)
program : 07
output:07
8. Special operators.
Comments
Post a Comment