• Post Reply Bookmark Topic Watch Topic
  • New Topic

doubt about assignments  RSS feed

 
Harivenkatesh Polnati
Greenhorn
Posts: 25
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
i have a doubt regarding below program
class Prog
{
public static void main(String[] args)
{
int a,b,c,d;
a=b=c=d=100;
a+=b*=c/=d%=20;
System.out.println("a......."+a+"b.........."+b+"c.........."+c+"d........."+d);
}
}
i got a=1320,b=1210,c=11,d=10
so, what is the values of a,b,c,d and please explain the a+=b*=c/=d%=20; equation assignment process
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harivenkatesh Polnati wrote:
i got a=1320,b=1210,c=11,d=10
so, what is the values of a,b,c,d and please explain the a+=b*=c/=d%=20; equation assignment process

It doesn't look like you actually ran this code, did you? You can break this down into its equivalent:

Note that evaluation starts from the right and proceeds to the left. What you have is fundamentally a series of assignment statements so the order of precedence of math operators does not come into play here.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!