• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Loop

 
zarina mohammad
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the following example is from Dan's mock exam.

the output on my system was 3 ,6 ,8 ,10 ,13 ,15 ,17,20.
but actually given as 3,5,9,11,14,16,19
why is the o/p varying in my system?
can someone try this code. And tell me the result.
thanks
zarina
[ January 12, 2003: Message edited by: Marilyn de Queiroz ]
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ran the code and the ouput was the same as yours, namely 3, 6, 8, 10, 13, 15, 17, 20,
If you try to "execute" the code in your head, you'll see that the given answer cannot be correct.
First, i and j are 0. Then, i gets incremented twice (i=2) and j once (j=1). A first output i+j (3) is printed. The switch resolves to default and the execution continues at label1. i gets incremented twice again (i=4) and j once (j=2). The second output can only be 6 (i+j=6) and nothing else. From there on, it's clear that the given answer is wrong.
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are both correct. I apologize for the error.
The case statement for the value 3 was missing so the code did not produce the output that matches the answer. The easiest way for me to fix the bug was to add the missing case statement. Changing the answer would have been more difficult because that would require me to come up with a variety of new answer options that would be correct only if a person made a common mistake.
I added the fix to both the July 4 and July 8 versions of the exam on the web site and also to the xml source document.
Thank you.
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
moving this to Mock Exam Errata --- even though Dan has addressed the issue.
 
Amir Ghahrai
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To me, that looks like a blinking loop
 
kishor rao
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
same o/p here fellas, though the didnt copy and i had to fill in . <- did that appear as a smiley too?
 
John Lee
Ranch Hand
Posts: 2545
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Dan
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That question was from a very old version of the exam and it is no longer available on my web site. I removed the questions with triple nested loops. Also, I removed questions with unnecessarily complex switch statements.
Just as the question has been removed from the mock exam, this thread should be removed from this message board.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic