0
Help me to understand this program
3 Respuestas
+ 2
Sindhuja Selvakumar
This code will always return 0 because the random() method will generate a double value between 0 and 1 but both excluded.
Your (int) will always truncate the decimal values produced by Math.random() and will result in 0.
So 0*6 will give you 0 always.
For having different results you can do-
int b=(int)(Math.random()*a);
0
This code will return either 0 or 6.
Math random() returns a value between 0 and 1 and multiplying it with 6 and forcing it to integer will return either 0*6=0 or 1*6=6
0
Thanks ..