132k views
5 votes
Assume that rand is an object of the Random class.

Which of the following ranges is generated by this statement:
int number = rand.nextInt(72) - 57;
(A) [57..72]
(B) [57..127]
(C) [57..128]
(D) [57..129]

User Sato
by
7.3k points

1 Answer

2 votes

Final answer:

The correct range of values generated by the statement 'int number = rand.nextInt(72) - 57' is [57..128], not accounting for the typo mentioned in the question.

Step-by-step explanation:

The question asks which range of values is generated by the Java statement int number = rand.nextInt(72) - 57; where rand is an object of the Random class. The nextInt(72) method call generates a random number in the range from 0 (inclusive) to 72 (exclusive), meaning the possible values are 0 to 71. Subtracting 57 from each of these values gives a new range from -57 (0 - 57) to 14 (71 - 57).

Therefore, the correct answer is : Option C: [57..128]. This accounts for all possible values that the rand.nextInt(72) - 57 expression can produce.

User Rfay
by
8.6k points