
java.lang.ArrayIndexOutOfBoundsException: 3
Publicado por steven (1 intervención) el 22/09/2017 17:20:08
Hola tengo este codigo, y a la hora de implementarlo me sale este error, ¿como puedo corregirlo?
adju
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import java.util.Random;
/**
*
* @author steven.henao
*/
public class matriz {
int fila;
int columna;
int nivel;
Random entero = new Random();
int mat[][] ;
public matriz(int fila, int columna) {
this.fila = fila;
this.columna = columna;
int matriz[][]= new int[this.fila][this.columna];
for(int h=0;h<fila;h++){
for(int k=0;k<columna;k++){
matriz[h][k]=0;
}
}
mat = matriz;
}
public int getFila() {
return fila;
}
public void setFila(int fila) {
this.fila = fila;
}
public int getColumna() {
return columna;
}
public void setColumna(int columna) {
this.columna = columna;
}
public int getNivel() {
return nivel;
}
public void setNivel(int nivel) {
this.nivel = nivel;
}
public Random getEntero() {
return entero;
}
public void setEntero(Random entero) {
this.entero = entero;
}
public int[][] getMat() {
return mat;
}
public void setMat(int[][] mat) {
this.mat = mat;
}
public void movimiento(int i, int j, int x){
int mat[][]= getMat();
int valor = mat[i][j];
switch (x){
case 1 :
i++;
j++;
if((i>=0)&&(j>=0)&&(j<=getColumna())&&(i<=getFila())){
mat[i][j]= valor++;
setMat(mat );
break;
}
case 2 :
j++;
if((i>=0)&&(j>=0)&&(j<=getColumna())&&(i<=getFila())){
mat[i][j]= valor++;
setMat(mat );
break;
}
case 3 :
i--;
j++;
if((i>=0)&&(j>=0)&&(j<=getColumna())&&(i<=getFila())){
mat[i][j]= valor++;
setMat(mat );
break;
}
case 4 :
i--;
if((i>=0)&&(j>=0)&&(j<=getColumna())&&(i<=getFila()) ){
mat[i][j]= valor++;
setMat(mat );
break;
}
case 5 :
i--;
j--;
if((i>=0)&&(j>=0)&&(j<=getColumna())&&(i<=getFila())){
mat[i][j]= valor++;
setMat(mat );
break;
}
case 6 :
j--;
if((i>=0)&&(j>=0)&&(j<=getColumna())&&(i<=getFila()) ){
mat[i][j]= valor++;
setMat(mat );
break;
}
case 7 :
i++;
j--;
if((i>=0)&&(j>=0)&&(j<=getColumna())&&(i<=getFila())){
mat[i][j]= valor++;
setMat(mat );
break;
}
case 8 :
i++;
if((i>=0)&&(j>=0)&&(j<=getColumna())&&(i<=getFila()) ){
mat[i][j]= valor++;
setMat(mat );
break;
}
}
}
public void llenarMatriz(){
int i = 2;
int j = 2;
mat[i][j]= 1;
for(int k=1;k<=(getFila()*getColumna());k++){
int x = entero.nextInt(9)+1;
movimiento(i, j, x);
}
}
public void mostrarMatriz(){
// int mat[][]= getMat();
for(int i=1; i<= getFila(); i++){
for(int j=1; j<= getColumna(); j++){
System.out.print(mat[i][j]);
}
System.out.println();
}
}
}
adju
Valora esta pregunta


0