Different types of operators in java which are given below:
- Unary Operator,
- Arithmetic Operator,
- Shift Operator,
- Relational Operator,
- Bitwise Operator,
- Logical Operator,
- Ternary Operator and
- Assignment Operator.
Unary Operator:- It is used to increment or decrement a value by one.
i++, i-- (Postfix)
++i, --i (Prefix)
Postfix-first print then increment.
Prefix-first increment then print.
Example
class OperatorExample{
public static void main(String args[])
{
int x=10;
System.out.println(x++);
System.out.println(++x);
System.out.println(x--);
System.out.println(--x);
}
}
Output 10 12 12 10.
Arithmetic Operator:-
It can be used to perform mathematical operations such as addition, subtraction, multiplication, and division (+,-,*,/).
Example
class student
{
public static void main(String args[])
{
int a=22;
int b=10;
System.out.println(a+b);
System.out.println(a-b);
System.out.println(a*b);
System.out.println(a/b);
}
}
Output 32 12 220 2.2.
If we use third variables to store the result are:-
class student
{
public static void main(String args[])
{
int m=22;
int n=10;
int c;
c=m+n;
System.out.println(c);
c=m-n;
System.out.println(c);
c=m*n;
System.out.println(c);
c=m/n;
System.out.println(c);
}
}
Output- 32 12 220 1.2 .
Khushi Singh
24-Feb-2025Java has eight major operator types for processing variable and value data.