Which of the following expressions yields an integer between 0 and 100, inclusive? Question 5 options: (int)(Math.random() * 100 + 1) (int)(Math.random() * 101) (int)(Math.random() * 100) (int)(Math.random() * 100) + 1

Respuesta :

Answer:

(b) (int)(Math.random() * 101)

Explanation:

Given

[tex]min = 0[/tex] --- minimum

[tex]max =100[/tex] --- maximum

Required

Java expression to generate random integer between the above interval

The syntax to do this is:

(int)(Math.random((max - min) + 1) + min)

Substitute the values of max and min

(int)(Math.random((100 - 0) + 1) + 0)

Simplify the expression

(int)(Math.random(100 + 1) + 0)

(int)(Math.random(101) + 0)

(int)(Math.random(101))

Hence, the right option is:

(b) (int)(Math.random() * 101)