Various Type Of Operator In JAVA
There are six types of assignment operator in java
No | Operator | USD | Description |
---|---|---|---|
1 | = | c = a + b | Simple Assignment |
2 | += | A=A+B(a+=B) | Addition assignment |
3 | -= | B=B-a(b-=a) | Subtraction assignment |
4 | *= | c=c*a(C*=A) | Multiplication assignment |
5 | /= | b=b/a(B/=a) | Division assignment |
6 | %= | B=B%a(B%=a) | Modulus assignment |
1) Simple Assignment
- Simple assignment operator in assigns a value from right side operand to left side operand (name of an operator)
Example
public class SimpleAssignment {
public static void main(String[] args) {
int a = 10;
int b = 20;
// assign the value of a+b into c
int c = a + b ;
System.out.println("value of c "+c);
}
}
Output
value of c 30
2) Addition Assignment
- Addition Assignment operator uses two operators to add and assignment
- Add right operand to left operand and assign the result of the left operand
Example
public class AdditionAssignment {
public static void main(String[] args) {
int a = 24;
int c= 24;
System.out.println("Before value of c = "+c);
//assign the value of a and c into c
//here internal process " c=c+a "
c += a;
System.out.println("Final value of c = "+c);
}
}
Output
Before value of c = 24
Final value of c = 48
3) subtraction Assignment
- subtraction assignment operator use two operators subtracts and assignment
- subtracts right operand from the left operand and assign the result two left operand
Example
public class SubtractionAssignment {
public static void main(String[] args) {
int m=10;
int q=25;
System.out.println("Befor value of q = "+q);
//subtraction in q
//internal process "q=q-a"
q -= m;
System.out.println("Final value of q = "+q);
}
}
Output
Befor value of q = 25
Final value of q = 15
4) Multiplication Assignment
- Multiplication Assignment operator uses two operator multiply and assignment
- Multiplies right operand with the left operand and assign the result to left operand
Example
public class MultiplicationAssignment {
public static void main(String[] args) {
int a= 10;
int t= 20;
System.out.println("Before value of t = "+t);
//multiplicationassignment of t
//internal process " t=t*a "
t *= a;
System.out.println("After assignment value of t = "+t);
}
}
Output
Before value of t = 20
After assignment value of t = 200
5) Division Assignment
- Division assignment operator use in two operator divide and assignment
- divide left operand with the right operand and assign the result to left operand
Example
public class DivisionASsignment {
public static void main(String[] args) {
int c=20;
int v=200;
System.out.println("Before the value of v = "+v);
//divisionassignment of v
//internal process "v = v/c"
v /= c ;
System.out.println("After assignment value of v = "+v);
}
}
Output
Before the value of v = 200
After assignment value of v = 10
6) Modulus Assignment
- modulus assignment operators use in two operator modulus and assignment
- modulus using two operands and assign the result of the left operand
Example
public class ModulusAssignment {
public static void main(String[] args) {
int d= 20;
int p= 225;
System.out.println("Before assignment value of p = "+p);
//assignment value of p
//internal process p = p % d
p %= d ;
System.out.println("After assignment value of p = "+p);
}
}
Output
Before assignment value of p = 225
After assignment value of p = 5
so it's all about in Assignment operator In Java With Example Program
Tags:
operator