Operators Java provides many types of operators which can be used according to the need is knows as Operators in JAVA. For example: +, -, *, / etc.
There are many types of operators in Java.
- Unary Operator
- Arithmetic Operator
- Shift Operator
- Relational Operator
- Bitwise Operator
- Logical Operator
- Ternary Operator
- Assignment Operator
Java Unary Operator
1. Example
Example of unary Operator
Input value
Java Unary operatorpublic class Operator{ public static void main(String args[]){ int x=5; System.out.println(x++); System.out.println(++x);
screen shot of Unary Operator
Output value
2. Example
Example of unary Operator
Input Values
Java Unary operatorpublic class Operator{ public static void main(String args[]){ int x=5; System.out.println(x--); System.out.println(--x);
screen shot of Unary Operator
Output Value
3. Example
Example of unary Operator
Input Values
Java Unary Operatorpublic class Operator{ public static void main(String args[]){ int x=25; int y=-30; boolean t=true; boolean o=false; System.out.println(~x); System.out.println(~y); System.out.println(!t); System.out.println(!o); }}
screen shot of Unary Operator
Output Value
JAVA Arithmetic Operator
Example of Arithmetic Operator
1. Example
Input Values
JAVA Arithmetic Operatorpublic class Operator{ public static void main(String args[]){ int x=52; int y=25; System.out.println(x+y); System.out.println(x-y); System.out.println(x*y); System.out.println(x/y); System.out.println(x%y); }}
Screen shot of Arithmetic Operator
Output Value
2.Example
Input Values
JAVA Arithmetic Operatorpublic class Operator{ public static void main(String args[]){ System.out.println(50+25/12*8-9*18/4); }}
Screen shot of Arithmetic Operator
Output Value
Shift Operators
There are three types of Shift Operator.
- Left Shift Operator
- Signed Right Shift Operator
- Unsigned Right shift operator
Java Left Shift Operators
Example of Left Shift Operators
Input Values
Java Left Shift Operatorpublic class Operator{ public static void main(String args[]){ System.out.println(25<<5); System.out.println(30<<6); System.out.println(35<<7); System.out.println(40<<8); System.out.println(45<<9); System.out.println(40<<5); }}
Screen shot of Left Shift Operators
Output Value
Java Right Shift Operators
Example of Right shift Operator
Input Values
Java Right Shift Operatorpublic class Operator{ public static void main(String args[]){ System.out.println(15>>2); System.out.println(30>>2); System.out.println(45>>3); System.out.println(60>>3); System.out.println(75>>4); System.out.println(90>>12); }}
Screen shot of Right shift Operator
Output Value
Java AND Operator
Example of AND Operator
Input Values
Java AND Operatorpublic class Operator{ public static void main(String args[]){ int x=35; int y=28; int z=49; System.out.println(x<y&&x<z); System.out.println(x<y&x<z); }}
Screen Shot of AND Operator
Output Value
Java OR Operators
Example of OR Operators
Input Values
Java OR Operatorpublic class Operator{ public static void main(String args[]){ int x=65; int y=25; int z=35; System.out.println(x>y||x<z); System.out.println(x>y|x<z); System.out.println(x>y||x++<z); System.out.println(x); System.out.println(x>y|x++<z); System.out.println(y); System.out.println(z); }}
Screen shot of OR Operators
Output Value
Java Ternary Operator
Example of Ternary Operator
Input Values
Java Ternary Operatorpublic class Operator{ public static void main(String args[]){ int x=45; int y=65; int min=(x<y)?x:y; System.out.println(min); }}
Screen shot of Ternary Operator
Output Value
Java Assignment Operator
Example of Assignment Operator
Input Value
Java Assignment Operatorpublic class Operator{ public static void main(String[] args){ int x=15; x+=5; System.out.println(x); x-=2; System.out.println(x); x*=3; System.out.println(x); x/=3; System.out.println(x); }}
Screen shot of Assignment Operator
Output Value
If you have any queries regarding this article or if I have missed something on this topic, please feel free to add in the comment down below for the audience. See you guys in another article.
To know more about JAVA Wikipedia please click here .
Stay Connected Stay Safe, Thank you
0 Comments