Menu
Topics Index
...
`


Operators >
Siva Nookala - 12 Apr 2016
Assignment operator is used to assign a value of an expression to a variable. Usual assignment operator we see is ' = '. e.g., a = 5;.

var = expression;

The type of var must be compatible with the type of expression. i.e. if the var is of type int, then expression should also be of type int. Multiple variables can be assigned a same value by chaining the assignment as shown below.
int x, y, z;

x = y = z = 100; // set x, y, and z to 100

System.out.print("x = " + x);
System.out.print(" y = " + y);
System.out.println(" z = " + z);
The other valid ways of using the assignment operator are:
int a = 100, b = 230, c = 240;
int m, n, o = 25;
int g = 20;
int h = 25;

0
Wrong
Score more than 2 points

© meritcampus 2016 - 2017

All Rights Reserved.

Learn Java Programming from our Experts in 30 Days