Originally posted by chao-long liao:
class Test {
public static void main(String[] args) {
int i = 2;
int j = (i=3) * i;
System.out.println(j);
}
}
ans:9
Can anybody tell me in detail,why the answer is 9??
thanks for help.
(), paranthesis, play a great role in mathematical equations
Here it overrides the earlier assignment of i. Assignments normally happen at the last in a equation. (if you remove () you will get j=6).
Since there is a paranthesis, i=3 happens first , so thats a square (ie i*i) resulting 9
HTH