+ 1
Why does this problem print 0?
int a = 6; int b = (int)Math.random() * a; System.out.print(b);
1 Answer
0
You need to add brackets:
int b = (int)(Math.random() * a);
This calcs first Math.random() * a and then converts it to integer.
Math.random() returns a double between 0 - 1. If you first convert it to integer it gives you always 0.