Mastering Java: The Ultimate 2025 All-In-One Quiz to Excel in 'Thinking in Java

Image Description

Question: 1 / 510

What will be the output range of 'rand.nextInt(100) + 1' in Java?

0 to 100

1 to 100

This is because when using rand.nextInt(100), the numbers generated are between 0 (inclusive) to 100 (exclusive), so adding 1 to the result will give a range of 1 to 100. Options A and D are incorrect because the lower bound is not inclusive in rand.nextInt(), therefore the range cannot include 0. Option C is incorrect because adding 1 to the result will give a range of 1 to 101, which is not correct based on the parameters of rand.nextInt(100).

Get further explanation with Examzify DeepDiveBeta

1 to 101

0 to 99

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy