|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 thyx 于 2017-2-22 00:24 编辑
- class It {
- static int size;
- public It(int size) {
- It.size=size;
- }
- private static java.util.Random rand = new java.util.Random();
- static DotInfo[][] dotlength = new DotInfo[size][size];
- public DotInfo[][] getDot(){
-
-
- for(int j = 0; j<size; j++){
- for(int i = 0; i<size; i++){
- dotlength[j][i]=new DotInfo(j,i,rand.nextInt(6)+0);//dotInfo有三个值(x,y,color),color用一些随机的数字表示
- }
- }
- return dotlength;
- }
- public void dot(){
- getDot();
- for(int i =0;i<dotlength.length;i++){
- for(int s =0;s<dotlength[i].length;s++){
- System.out.println(dotlength[i][s]);
- }
- }
- }
- }
- public class FloodIt{
- public static void main(String[] args) {
- It t= new It(5);
- t.dot();
- }
- }
复制代码
为什么超出范围
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
讲这行超出 dotlength[j][i]=new DotInfo(j,i,rand.nextInt(6)+0);
|
|