The five arithmetic assignment operators are a form of short hand. Various textbooks call them "compound assignment operators" or "combined assignment operators". Their usage can be explaned in terms of the assignment operator and the arithmetic operators.
Compound Operator | Sample Expression | Expanded Form |
---|---|---|
+= | x+=2 | x=x+2 |
-= | y -=6 | y=y-6 |
*= | z *=7 | z=z*7 |
/= | a /=4 | a=a/4 |
%= | b %=9 | b= b%9 |
This Java program defines a class called Assignment which contains a main() method that performs arithmetic operations using assignment operators on an integer variable a. The program prints the value of a after each operation using System.out.println() method. Here is the breakdown of the operations performed in the program:
public class Assignment { public static void main(String args[]) { int a=123; System.out.println(a); a+=10; System.out.println(a); a-=10;//a=a-10 System.out.println(a); a*=10; System.out.println(a); a/=10; System.out.println(a); a%=10; System.out.println(a); } }
123 133 123 1230 123 3To download raw file Click Here
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions