Introduction to Assignment Operators
Assignment operator is one of Java operators. Simple assignment operator “=” contains two operands. It assigns the value on its right operand to the operand on its left. For example, the assignment operator is used to assign a value to a variable.
Syntax
operand = operand;
Example
1. /**
2. * @(#)SimpleAssignmentOperatorDemo.java
3. *
4. *
5. * @author
6. * @version 1.00 2009/11/2
7. */
8.
9. public class SimpleAssignmentOperatorDemo {
10.
11. /**
12. * Creates a new instance of SimpleAssignmentOperatorDemo.
13. */
14.
15. public SimpleAssignmentOperatorDemo() {
16. }
17.
18. /**
19. * @param args the command line arguments
20. */
21. public static void main(String[] args) {
22. // TODO code application logic here
23.
24. int b = 100; // Assign 100 to variable b by assignment operator "="
25.
26. int c = b; // Assign value of b to variable c
27.
28. System.out.println("Value of b is: " + b);
29. System.out.println("Value of c is: " + c);
30.
31. }
32. }
Output
Value of b is: 100
Value of c is: 100
