• 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:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

loop

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Got confused with the code..
Why is the output 8???
Chitra
 
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Inserting some System.out.prinln will help
 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gururs:
Is not unrealistic that such a tidious question is expected to be answered in exam in 2 minutes?
Or it is not a exam like question?
 
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
Those kind of questions are not to be expected in the real exam but they are d**n good exercises for learning how to analyze code. If the exam pops up a loooooong code snippet like this one, just remember that there is a trick somewhere, that the loop only executes one or two times due to some obscure condition and the whole analysis gets easier. Do not be impressed by the length of the code, but learn how to decipher it quickly and efficiently. That way you may gain minutes instead of losing them
 
Chitra Jay
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question was from JQ+ Real Brainer section. But,the actual for loop was
for (int i=10; i<0; i--) instead of the one i posted.So the whole for loop never gets executed at all.
But,I purposely wanted to make the loop condition evaluate to true and find out what the program really does..
I too spent a lot of minutes on this one..Hope such tough ones doesnt appear in the real exam
Valentin,Thanks for your tip!!
Chitra
 
No more fooling around. Read this tiny ad:
The new gardening playing cards kickstarter is now live!
https://www.kickstarter.com/projects/paulwheaton/garden-cards
reply
    Bookmark Topic Watch Topic
  • New Topic