This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.

How can I check the answers in the mock exam? I clicked submit and it gave me a score but I was not able to see the correct answers... Thanks.

sun par
Ranch Hand

Joined: Oct 03, 2002
Posts: 257

posted

0

The questions were tough.. Will it be this tough in the real exam also? Thanks

sun par
Ranch Hand

Joined: Oct 03, 2002
Posts: 257

posted

0

Hai Valentin, The question below states that there are 2 correct answers... ButI think that only C is correct... -------------------------------------------------- Question 16. What is the output of the following code when compiled and run? Select two correct answers. public class Question16 { public static void main(String[] args) { int i = 2; try { if((i/=(int)Math.floor(Math.random())) > 1) System.out.println("No arithmetic exception"); } catch (ArithmeticException ae){ System.err.println("Arithmetic exception caught"); } } }

A. Compilation error. B. No arithmetic exception will never be printed. C. The final value of i is 2. D. The final value of i is 0. E. The try-catch block is necessary for the code to compile. ------------------------------------------------- Thanks

Originally posted by sun par: The question below states that there are 2 correct answers... ButI think that only C is correct... ((i/=(int)Math.floor(Math.random())) > 1)

Math.random() - Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0. So the result will always be less than 1. Math.floor() - Returns the largest (closest to positive infinity) double value that is not greater than the argument and is equal to a mathematical integer So it always truncate the result of Math.random() to zero. Therefore the expression will always generate a divide-by-zero error. The correct answers are B and C.

Originally posted by sun par: The questions were tough.. Will it be this tough in the real exam also? Thanks

The real exam won't be that hard. I intentionally made this mock exam hard to provide a little more challenge for people who want to get this a little further and seek for a very good score.