Answer:
Question 1: (int)(Math.random() * (upper − lower) ) + lower
This function will generate a value for secret number. As given that lower limit and upper limit are exclusive so this function will generate a value between upper bound and lower bound but not exceed the bounds.
Question 2: I only
The given while condition says that the loop will continue until the userGuess is not equal to the secretNumber. The similar condition is depicted in the 1st option that says unless userGuess not becomes equal to secretNumber continue performing the do block.
Question 3: -3
According to given scenario the while block operates until value of x becomes less than zero.
- As x is initiated as 15, it is greater than one so 6 will be subtracted from it as depicted.
- The answer will be 9 that is again greater than 0 so 6 will be subtracted again which gives 3.
- Checking for while condition it again is greater than 0 so 6 will be subtracted from 0 giving -3.
- As now while condition = false so the last value of x which is -3 is printed.
Question 4: The value of answer is N
In this question we have to determine the answer when the while loop terminates. As the while loop terminates when the condition inside the while brackets is true. So the given condition inside the while brackets depicts that answer will be true when it will be equal to N. So when while loop will be terminated, the answer would be N.
Question 5: while( !(userGuess == secretNumber) || numGuesses < 15 )
In this statement, while loop will be terminated only in two conditions that are:
- When the number guessed by user is equal to the secret number. The loop will terminate ending the game.
- When the number of guesses from the user reaches 15 the while loop will terminate and end the game.
I hope it will help you!