Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups −
- 1. Arithmetic Operators : Arithmetic operators are used in mathematical Expressions in the same way that they are used in algebra.
- Addition,Subtraction,Multiplication,Division,Modulus.
- Example
- int a=10;
- int b=20;
- int c=a+b;
- int d=a-b;
- int e=a*b;
- float f=a/b;
- 2. Relational Operators : == , != , < , > , <= , >=
- Example
- int a=10;
- int b=20;
- System.out.println(a<b);
- System.out.println(a>b);
- System.out.println(a<=b);
- System.out.println(a>=b);
- System.out.println(a!=b);
- System.out.println(a==b);
- 3. Logical Operators : AND operator : &&
- OR operator : ||
- NOT operator : !
- Example
- c1 && c2 = Ans
- T T T
- T F F
- F T F
- F F F
- c1 || c2 = Ans
- T T T
- T F T
- F T T
- F F F
4. Unary operators : i++ :- print first and then increment (post)
++i :- increment first and then print(pre)
Example
int a=10;
int b=20;
System.out.println("value"+ (a++)); // post = 10+1=11
System.out.println("value"+ (++b)); //pre= 20+1=21
Comments
Post a Comment