请问代码中的countArray[i]的值是怎么来的啊?
publicclassFourthExam{publicstaticvoidmain(String[]args){int[]countArray=newint[11];f...
public class FourthExam{
public static void main(String[] args){
int[] countArray = new int[11];
for(int i=0;i<36000;i++){
int num1 = (int)(Math.random()*6+1);
int num2 = (int)(Math.random()*6+1);
countArray[num1+num2-2]++;
}
for(int i=0;i<countArray.length;i++){
System.out.println((i+2)+" "+countArray[i]+" "+(int)((countArray[i]/36000.0)*100)+"%");
}
}
} 展开
public static void main(String[] args){
int[] countArray = new int[11];
for(int i=0;i<36000;i++){
int num1 = (int)(Math.random()*6+1);
int num2 = (int)(Math.random()*6+1);
countArray[num1+num2-2]++;
}
for(int i=0;i<countArray.length;i++){
System.out.println((i+2)+" "+countArray[i]+" "+(int)((countArray[i]/36000.0)*100)+"%");
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询