0
11th Apr 2020, 7:44 AM
Sindhuja Selvakumar
Sindhuja Selvakumar - avatar
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);
11th Apr 2020, 8:02 AM
Avinesh
Avinesh - avatar
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
11th Apr 2020, 7:50 AM
Souptik Nath
Souptik Nath - avatar
0
Thanks ..
11th Apr 2020, 8:08 AM
Sindhuja Selvakumar
Sindhuja Selvakumar - avatar