aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes question about OperandOrder Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "question about OperandOrder" Watch "question about OperandOrder" New topic
Author

question about OperandOrder

michael wang
Ranch Hand

Joined: Feb 06, 2002
Posts: 35
public class OperandOrder {
public static void main(String args[]) {
int i=0;
int a[] = {3,6};
a[i] = i = 9;
System.out.println(i + " " + a[0] + " " + a[1]);
}
}

the code above prints
9 9 6
how can i get it?


--<br />a java beginner from China
Brian Lugo
Ranch Hand

Joined: Nov 10, 2000
Posts: 165
First evaluate the array variable as [] operator has the highest precedence. This will give you:
a[0] = i = 9;
The associativity of = operator is from right to left. So i will be assigned 9 and a[0] will be assigned 9 after that.
This justifies what is printed.
Brian
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question about OperandOrder