50.2k views
0 votes
What is the output from system.out.println((int)(math.random() * 4))?

User Mmik
by
7.7k points

1 Answer

6 votes
In java, the math.random() function call will return a random number between 0 and 1. Therefore, the call 'math.random() * 4' will return a number between 0 and 4. The casting of this call to an integer '(int)' will return an integer with no fraction, so numbers 0, 1, 2, 3 or 4.
User Cully
by
8.2k points