difference between..(int)2.56 and Math.random(2.56)....in java
Answers
Answered by
1
Answer:
The (int) casts the double result of Math.random() to an integer. So (int) Math.random() always is zero, because random() returns a number greater than or equal to 0.0 and less than 1.0
int i = (int)Math.random();
double d = Math.random();
System.out.println(i);
System.out.println(d);
If you need integer randoms, you need first to multyply the result of random
int factor = 100;
i = (int)(Math.random() * factor);
System.out.println(i);
Explanation:
Similar questions