Opening Hours :7AM to 9PM
Operator is a symbol which are used to perform particular operation.
In java language these opeatrs are classified into following types.
1. Unary Operators
2. Binary Operators
3. Ternary Operators
If any operation perform on single operand (Variable) is known as uanry operator.
These operators are classified into following types.
1. Unary Minus Operator
2. Increment Operator
3. Decrement Operator
Unary minus means sign value or minus value
Example:
int x=10;
then -x=-10;
public class Main { public static void main(String args[]) { int x=10; System.out.println("The Sign value is "+(-x)); } }
public class Main { public static void main(String args[]) { int x; x=Integer.parseInt(args[0]); System.out.println("The Sign value is "+(-x)); } }
import java.util.*; public class Main { public static void main(String args[]) { int x; Scanner s=new Scanner(System.in); System.out.println("Enter x Value"); x=s.nextInt(); System.out.println("The Sign value is "+(-x)); } }
Increment Operator is used to increment the one value to the current value. These are classified into following types.
1.PreIncrement operator
2.PostIncrement operator
PreIncrement oprator is used to increment the value first assign the value later.
Example:
int x=10;
then ++x=11;
public class Main { public static void main(String args[]) { int x=10; System.out.println("The PreIncrement value is "+(++x)); } }
public class Main { public static void main(String args[]) { int x; x=Integer.parseInt(args[0]); System.out.println("The PreIncrement value is "+(++x)); } }
import java.util.*; public class Main { public static void main(String args[]) { int x; Scanner s=new Scanner(System.in); System.out.println("Enter x Value"); x=s.nextInt(); System.out.println("The PreIncrement value is "+(++x)); } }
In the post incrementation assign the value first increment the value later.
Example:
int x=10;
then x++=10;
public class Main { public static void main(String args[]) { int x=10; System.out.println("The PostIncrement value is "+(x++)); } }
public class Main { public static void main(String args[]) { int x; x=Integer.parseInt(args[0]); System.out.println("The PostIncrement value is "+(x++)); } }
import java.util.*; public class Main { public static void main(String args[]) { int x; Scanner s=new Scanner(System.in); System.out.println("Enter x Value"); x=s.nextInt(); System.out.println("The PostIncrement value is "+(x++)); } }
Decrement Operator is used to decrement the one value to the current value. These are classified into following types.
1.PreDecrement operator
2.PostDecrement operator
PreDecrement Operator(--x):
PreDecrement oprator is used to Decrement the value first assign the value later.
Example:
int x=10;
then --x=9;
public class Main { public static void main(String args[]) { int x=10; System.out.println("The PreDecrement value is "+(--x)); } }
public class Main { public static void main(String args[]) { int x; x=Integer.parseInt(args[0]); System.out.println("The PreDecrement value is "+(--x)); } }
import java.util.*; public class Main { public static void main(String args[]) { int x; Scanner s=new Scanner(System.in); System.out.println("Enter x Value"); x=s.nextInt(); System.out.println("The PreDecrement value is "+(--x)); } }
In the post Decrement assign the value first decrement the value later.
Example:
int x=10;
then x--=10;
public class Main { public static void main(String args[]) { int x=10; System.out.println("The PostDecrementvalue is "+(x--)); } }
public class Main { public static void main(String args[]) { int x; x=Integer.parseInt(args[0]); System.out.println("The PostDecrement value is "+(x--)); } }
import java.util.*; public class Main { public static void main(String args[]) { int x; Scanner s=new Scanner(System.in); System.out.println("Enter x Value"); x=s.nextInt(); System.out.println("The PostDecrement value is "+(x--); } }
If any operation perform on two operands(variable) is known as binary operators.
In java language these opeatrs are classified into following types.
1.Arithmetic Operators
2.Assignment Operators
3.Relational Operators
4.Logical Operators
5.Bitwise Operators
These are the operands can be used to perform simple mathametical operation. Which are classified into following types.
Operator | Operation | Example | Program |
---|---|---|---|
+ | Addition | x+y | Program |
- | Substraction | x-y | Program |
* | Multiplication | x*y | Program |
/ | Division | x/y | Program |
% | Modular Division | x%y | Program |
public class Main { public static void main(String args[]) { int x=10,y=20,z; z=x+y; System.out.println("Addition is "+(z)); } }
public class Main { public static void main(String args[]) { int x,y,z; x=Integer.parseInt(args[0]); y=Integer.parseInt(args[1]); z=x+y; System.out.println("Addition is "+(z)); } }
import java.util.*; public class Main { public static void main(String args[]) { int x,y,z; Scanner s=new Scanner(System.in); System.out.println("Enter x,y values"); x=s.nextInt(); y=s.nextInt(); z=x+y; System.out.println("Addition is "+(z)); } }
Assignment operators are used to assign the values to the variable or assign the variable to variable
There are classified into following types.
Operator | Example | Same As |
---|---|---|
= | x=y | x=y |
+= | x+=y | x=x+y |
-= | x-=y | x=x-y |
*= | x*=y | x=x*y |
/= | x/=y | x=x/y |
%= | x%=y | x=x%y |
public class Main { public static void main(String args[]) { int x=10,y=20,z; z=x; x=y; y=z; System.out.println("x value is: "+(x)); System.out.println("y value is: "+(y)); } }
public class Main { public static void main(String args[]) { int x,y,z; x=Integer.parseInt(args[0]); y=Integer.parseInt(args[1]); z=x; x=y; y=z; System.out.println("x value is: "+(x)); System.out.println("y value is: "+(y)); } }
import java.util.*; public class Main { public static void main(String args[]) { int x,y,z; Scanner s=new Scanner(System.in); System.out.println("ENter x,y values"); x=s.nextInt(); y=s.nextInt(); z=x; x=y; y=z; System.out.println("x value is: "+(x)); System.out.println("y value is: "+(y)); } }
public class Main { public static void main(String args[]) { int x=10,y=20; x=x+y; y=x-y; x=x-y; System.out.println("x value is: "+(x)); System.out.println("y value is: "+(y)); } }
public class Main { public static void main(String args[]) { int x,y,z; x=Integer.parseInt(args[0]); y=Integer.parseInt(args[1]); x=x+y; y=x-y; x=x-y; System.out.println("x value is: "+(x)); System.out.println("y value is: "+(y)); } }
import java.util.*; public class Main { public static void main(String args[]) { int x,y,z; Scanner s=new Scanner(System.in); System.out.println("Enter x,y values"); x=s.nextInt(); y=s.nextInt(); x=x+y; y=x-y; x=x-y; System.out.println("x value is: "+(x)); System.out.println("y value is: "+(y)); } }
Relational operators are used to check the relation between two variables. These are classified into following types
Operator | Example |
---|---|
== | x==y |
< | x<y |
> | x>y |
<= | x<=y |
>= | x>=y |
!= | x!=y |
public class Main { public static void main(String args[]) { int x=10,y=20; boolean z; z=x>y; System.out.println("z value is: "+(z)); } }
public class Main { public static void main(String args[]) { int x,y; boolean z; x=Integer.parseInt(args[0]); y=Integer.parseInt(args[1]); z=x>y; System.out.println("z value is: "+(z)); } }
import java.util.*; public class Main { public static void main(String args[]) { int x,y; boolean z; Scanner s=new Scanner(System.in); System.out.println("Enter x,y values"); x=s.nextInt(); y=s.nextInt(); z=x>y; System.out.println("z value is: "+(z)); } }
Logical Operators are used to combine the morethan one condition. These are classified into following types.
Operator | Example |
---|---|
&& | x>y && x>z |
|| | x>y || x>z |
! | !(x>y && x>z) !(x>y || x>z) !(x>y) && !(x>z) !(x>y) || !(x>z) |
public class Main { public static void main(String args[]) { int x=10,y=20,z=30; boolean p; p=x>y && x>z; System.out.println("p value is: "+(p)); } }
public class Main { public static void main(String args[]) { int x,y,z; boolean p; x=Integer.parseInt(args[0]); y=Integer.parseInt(args[1]); z=Integer.parseInt(args[2]); p=x>y && x>z; System.out.println("p value is: "+(p)); } }
import java.util.*; class Main { public static void main(String args[]) { int x,y,z; boolean p; Scanner s=new Scanner(System.in); System.out.println("Enter x,y,z values"); x=s.nextInt(); y=s.nextInt(); z=s.nextInt(); p=x>y && x>z; System.out.println("p value is: "+(p)); } }
Bitwise Operators are used to perform any operaion on binary(0 and 1) values.These are classified into following types
Operator | Operation | Example | Program |
---|---|---|---|
& | AND | x & y | Program |
| | OR | x|y | Program |
^ | CAP | x ^ y | Program |
~ | NAGETION | ~x | Program |
<< | LEFT SHIFT | x<<y | Program |
>> | RIGHT SHIFT | x>>y | Program |
public class Main { public static void main(String args[]) { int x=10,y=15,z z=x & y; System.out.println("z value is: "+(z)); } }
public class Main { public static void main(String args[]) { int x,y,z; x=Integer.parseInt(args[0]); y=Integer.parseInt(args[1]); z=x & y; System.out.println("z value is: "+(z)); } }
import java.util.*; public class Main { public static void main(String args[]) { int x,y,z; Scanner s=new Scanner(System.in); System.out.println("Enter x,y values"); x=s.nextInt(); y=s.nextInt(); z=x & y; System.out.println("z value is: "+(z)); } }
Ternary operator is used to perform any operation on three operands
Expression1 ? Expression2 : Expression3;
Here
Expression1 is a condition
Expression2 is a operation
Expression3 is a operation
In the above syntax
if condition is true ,The statements of Expression2 is execute.
if condition is false ,The statements of Expression3 is execute
public class Main { public static void main(String args[]) { int x=10; String s = x%2==0 ? "Even Number" : "Odd Number"; System.out.println(s); } }
public class Main { public static void main(String args[]) { int x; x=Integer.parseInt(args[0]); String s; s= x%2==0 ? "Even Number" : "Odd Number"; System.out.println(s); } }
import java.util.*; public class Main { public static void main(String args[]) { int x; Scanner s1=new Scanner(System.in); System.out.println("Enter x value"); x=s1.nextInt(); String s; s= x%2==0 ? "Even Number" : "Odd Number"; System.out.println(s); } }
class Main { public static void main(String args[]) { int x=10,y=20; String s; s= x>y ? "x is Max Number" : "y is Max Number"; System.out.println(s); } }
public class Main { public static void main(String args[]) { int x,y; x=Integer.parseInt(args[0]); y=Integer.parseInt(args[1]); String s; s= x>y ? "x is Max Number" : "y is Max Number"; System.out.println(s); } }
import java.util.*; public class Main { public static void main(String args[]) { int x,y; Scanner s1=new Scanner(System.in); System.out.println("Enter x ,y value"); x=s1.nextInt(); y=s1.nextInt(); String s; s= x>y ? "x is Max Number" : "y is Max Number"; System.out.println(s); } }
public class Main { public static void main(String args[]) { int x=10,y=20,z=30 String s; s=(x > y) ?(x > z ? "x is Max" : "z is Max") :(y > z ? "y is Max" : "z is Max"); System.out.println(s); } }
public class Main { public static void main(String args[]) { int x,y,z; x=Integer.parseInt(args[0]); y=Integer.parseInt(args[1]); z=Integer.parseInt(args[2]); String s; s=(x > y) ?(x > z ? "x is Max" : "z is Max") :(y > z ? "y is Max" : "z is Max");
System.out.println(s); } }
import java.util.*; public class Main { public static void main(String args[]) { int x,y,z; Scanner s1=new Scanner(System.in); System.out.println("Enter x ,y ,z value"); x=s1.nextInt(); y=s1.nextInt(); z=s1.nextInt(); String s; s=(x > y) ?(x > z ? "x is Max" : "z is Max") :(y > z ? "y is Max" : "z is Max"); System.out.println(s); } }
public class Main { public static void main(String args[]) { int a=2000,d=2,i=2,si; si= (a*d*i)/100; System.out.println("Simple Interest is: "+(si)); } }
public class Main { public static void main(String args[]) { int a,d,i,si; a=Integer.parseInt(args[0]); d=Integer.parseInt(args[1]); i=Integer.parseInt(args[2]); si= (a*d*i)/100; System.out.println("Simple Interest is: "+(si)); } }
import java.util.*; public class Main { public static void main(String args[]) { int a,d,i,si; Scanner s=new Scanner(System.in); System.out.println("Enter Amount:"); a=s.nextInt(); System.out.println("Enter Duration:"); d=s.nextInt(); System.out.println("Enter Interest:"); i=s.nextInt(); si= (a*d*i)/100; System.out.println("Simple Interest is: "+(si)); } }