我写了代码,但是没有从double到int的转换。
public class Array {
public static void main(String[] args) {
int i;
int[] ar1 = new int[100];
for(int i = 0; i < ar1.length; i++) {
ar1[i] = int(Math.random() * 100);
System.out.print(ar1[i] + " ");
}
}
}
如何纠正?
最佳答案
ar1[i] = (int)(Math.random() * 100);
Java 中的转换看起来像 C 中的强制转换。
关于java - 如何使用类 Math 用从 0 到 99 的随机数填充数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25768435/