• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

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
 
See where your hand is? Not there. It's next to this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic