Java Reference
In-Depth Information
Assignment Operator
Assignment operators come in existence when there is a need of assigning value of a spe-
cified expression to a given variable.
Instead of assignment operator, java also provides shorthand assignment operators with the
following syntax:
Variable operator = expression;
The above expression is equivalent to variable=variable operator (expression)
Shorthand Assignment Operator
Statement with simple assignment operator
Corresponding statements with shorthand
operator
P=p+1
P+=1
P=p-1
p-=1
P=p*(n+1)
P*=n+1
P=p/(n+1)
p/=n+1
P=p%q
P%=q
public class Demo1
{
public static void main(String args[])
{
int value = 10;
System. out .println( "value is " +value);
// Shorthand assignment operators
int a1 = 4;
int a2 = 8;
Search WWH ::




Custom Search