Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# Valentin's mock exam..

sun par
Ranch Hand
Posts: 257
Can anyone please tell me where I can find Valentin's mock exam?
Thanks.

Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
There you go:
Val's mock exam
Good luck

sun par
Ranch Hand
Posts: 257
Hai Valentin,
Thanks.. Will try it out...

sun par
Ranch Hand
Posts: 257
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
Posts: 257
The questions were tough.. Will it be this tough in the real exam also?
Thanks

sun par
Ranch Hand
Posts: 257
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

Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
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.

sun par
Ranch Hand
Posts: 257
Thank you for making things clear..

Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
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.