• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

a[i]=i=9

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, all, this one is from the JavaQuest Mock Exam,
What happens during execution of the following program?
1. public class OperandOrder {
2. public static void main(String args[]) {
3. int i=0;
4. int a[] = {3,6};
5. a[i] = i = 9;
6. System.out.println(i + " " + a[0] + " " + a[1]);
7. }
8. }
I'm confused about the answer: 9, 9, 6
could anybody explain how "a[i] = i = 9" is excuted?
Lucy
 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it will be 9,6,6
just check once more
itz bcos when we assign first
a[0] = i = 9; is done
then a[0] = 9;
is done
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the order od evaluation is left 2 right whereas for assignment the order of execution is right 2 left .
Hope this is clear
------------------
"Winners don't do different things
They do things differently"
 
reply
    Bookmark Topic Watch Topic
  • New Topic