主题:帮忙看下哪里错了,谢谢了
程序是随机产生1000个0—9之间的数,并统计个数。我想用数组去做,可是提示数组越界
。知道那错的人说下,谢了。我是个初学者
import java.io.*;
import javax.swing.JOptionPane;
public class count {
static final int[] numbers={0,1,2,4,5,6,7,8,9};
static final int[] count={0,0,0,0,0,0,0,0,0,0};
public static void main(String args[]) throws IOException{
BufferedReader reader=new BufferedReader(
new InputStreamReader(System.in ));
for(int i=0;i<1000;i++)
{ int result=(int)(Math.random()*9);
for(int j=0;j<10;j++){
if(result==numbers[j]) count[j]++;
}
}
String output="数字:";
for(int i=0;i<10;i++){
output+=numbers[i]+ ""+count[i]+ "";
}
JOptionPane.showMessageDialog(null,output,"paixu",JOptionPane.INFORMATION_MESSAGE);
}
}
运行提示数组越界。
。知道那错的人说下,谢了。我是个初学者
import java.io.*;
import javax.swing.JOptionPane;
public class count {
static final int[] numbers={0,1,2,4,5,6,7,8,9};
static final int[] count={0,0,0,0,0,0,0,0,0,0};
public static void main(String args[]) throws IOException{
BufferedReader reader=new BufferedReader(
new InputStreamReader(System.in ));
for(int i=0;i<1000;i++)
{ int result=(int)(Math.random()*9);
for(int j=0;j<10;j++){
if(result==numbers[j]) count[j]++;
}
}
String output="数字:";
for(int i=0;i<10;i++){
output+=numbers[i]+ ""+count[i]+ "";
}
JOptionPane.showMessageDialog(null,output,"paixu",JOptionPane.INFORMATION_MESSAGE);
}
}
运行提示数组越界。