This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "question about OperandOrder" Watch "question about OperandOrder" New topic

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.
I agree. Here's the link:
subject: question about OperandOrder
It's not a secret anymore!