So, the output of this function is 0.
It is only possible if java updates the values once the entire statement precending ‘;’ has completed. If that is the case, then what’s the point of having an equal to operation?
Shouldn’t it correspond to, z =x +y-(x+y);
<code>class HelloWorld {
public static void main(String[] args) {
int x = 10;
int y = 20;
int z = x += y -= x += y;
System.out.println(z);
}
}
</code>
<code>class HelloWorld {
public static void main(String[] args) {
int x = 10;
int y = 20;
int z = x += y -= x += y;
System.out.println(z);
}
}
</code>
class HelloWorld {
public static void main(String[] args) {
int x = 10;
int y = 20;
int z = x += y -= x += y;
System.out.println(z);
}
}
I ran the code, and this is what I could infere. I did try searching if my inference is correct, however I didn’t find anything on this?
New contributor
Janam b is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.