Win a copy of Java Challengers this week in the Java in General forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Question 28 val's mock

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Val, I've passed your mock exam with 67.8% (>2 hours ). It is an excellent mock exam!
Anyway, I have some doubt over the explanation on q28.
The current value of j (2) is printed unchanged since the loops have not been able to evaluate their update statements...
Actually, the j update statements are indeed evaluated, because if u modified the code to

it will print 3, which means that the j++ is evaluated.
Correct me if I am wrong.
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The update statement is the third part of the for statement:
for (ForInit;Expression;ForUpdate)
and in this code the ForUpdate is never executed because both loop break before the update for the inner loop occurs.
 
Eric Low
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In that case, I found the word "unchanged" confusing . Because in fact the j has been "changed" through an increment and a decrement.
Actually, there might be better words than "changed/unchanged"...
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By unchanged I meant that j still has its same initial value.
How would you change the explanation? Any comments are welcome
Thanks for your feedback Eric
 
Eric Low
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Something like that, maybe...
The value of j will remain the same, ie 2, after an increment and a decrement. It will be printed...
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok thanks Eric, I'll change that within one or two hours...
Done... Actually I have taken a more pragmatic approach to explain what is going on...
[ March 22, 2002: Message edited by: Valentin Crettaz ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic