Help coderanch get a
new server
by contributing to the fundraiser
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

# Question errors

Author
Posts: 201
• Number of slices to send:
Optional 'thank-you' note:
Three MC questions came from a test bank in a java book- that I think are wrong but I wanted your take on them and see if I am wrong...

#1

Based on the code above, if the value of y is found to be 2, what is a possible value of x? B
A.2C.5
B.3D.6

The answer key says B I say A

#2
Given the following switch statement where x is an int:

If x is currently equal to 5, what will the value of x be after the switch statement executes?
A.5C.7
B.6D.10

The answer says 7 but I test this program I got 11...

Finally

#3 How many times will the following loop iterate?

A.0C.10
B.1D.11

The answer key says D I ran this I got C 10

Now am I going crazy or all or did this Java author get these questions- blantanty wrong- or is it me..Thanks JC

Java Cowboy
Posts: 16084
88
• Number of slices to send:
Optional 'thank-you' note:
#1: The answer obviously cannot be B (x == 3) because x must be < 3 to set y to 2.

#2: There are no "break;" statements in the switch, so it computes:

x += 3;
x++;
x += 2;
x--;
x++;

so the result is 11. The answer 7 is certainly wrong.

#3: The answer is obviously 10, as you found out by running the code. At the end x will be 0 and it stops.

In which book did you find these? Send the author a note about these mistakes...

James Chegwidden
Author
Posts: 201
• Number of slices to send:
Optional 'thank-you' note:
The 5th edition of a popular Java series from AWL...

Greenhorn
Posts: 2
• Number of slices to send:
Optional 'thank-you' note:
The answers gvien by you are absolutely correct. Report the errors to the author.

Marshal
Posts: 79531
379
• Number of slices to send:
Optional 'thank-you' note:
. . . and welcome to the Ranch, Mr Sanaulla.

 These are the worst of times and these are the best of times. And this is the best tiny ad: We need your help - Coderanch server fundraiser https://coderanch.com/t/782867/Coderanch-server-fundraiser