How many types of operator used in Java?

Total Post:16

Points:112

 56  View(s)
Ratings:
Rate this:
 Operators in java:-
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 .

Answer

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.