127k views
1 vote
What is the largest value that can be generated from (int)(Math.random() * 20)?

1) 0
2) 19
3) 20
4) Cannot be determined

User Perivesta
by
7.4k points

1 Answer

4 votes

Final answer:

The largest value that can be generated from (int)(Math.random() * 20) is 19.

Step-by-step explanation:

The largest value that can be generated from (int)(Math.random() * 20) is 19.

The expression (int)(Math.random() * 20) generates a random number between 0 (inclusive) and 20 (exclusive). Since the number is casted to an integer using (int), it will truncate any decimal places and return the largest integer value less than or equal to the generated number. Therefore, the largest value that can be obtained is 19.

User Droidchef
by
8.5k points