File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Question errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Question errors" Watch "Question errors" New topic

Question errors

James Chegwidden
Ranch Hand

Joined: Oct 06, 2002
Posts: 201
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...


Based on the code above, if the value of y is found to be 2, what is a possible value of x? B

The answer key says B I say A

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?

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


#3 How many times will the following loop iterate?


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

Author and Instructor, my book
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15091

#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 += 2;

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...

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
James Chegwidden
Ranch Hand

Joined: Oct 06, 2002
Posts: 201
The 5th edition of a popular Java series from AWL...
mohammed sanaullah

Joined: Jul 03, 2007
Posts: 2
The answers gvien by you are absolutely correct. Report the errors to the author.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46367
. . . and welcome to the Ranch, Mr Sanaulla.
I agree. Here's the link:
subject: Question errors
It's not a secret anymore!