Java - qye valores tiene la variable j

 
Vista:

qye valores tiene la variable j

Publicado por Gregory (1 intervención) el 26/07/2021 23:45:51
public class matriz {
public static void main(String[] args) {
int dato = 1;
int matriz [] []= new int[3] [2];
for (int i = 0; i < matriz.length; i++) {
for (int j = 0; j < matriz[0].length; j++) {
matriz [i] [j] = dato;
dato=dato+1;
}
}
}
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Billy Joel
Val: 2.665
Oro
Ha mantenido su posición en Java (en relación al último mes)
Gráfica de Java

qye valores tiene la variable j

Publicado por Billy Joel (876 intervenciones) el 30/07/2021 18:15:37
Creo que esto es lo que necesitas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public static void main(String[] args) {
    int dato = 1;
    int matriz[][] = new int[3][2];
    for (int i = 0; i < matriz.length; i++) {
        for (int j = 0; j < matriz[0].length; j++) {
            matriz[i][j] = dato;
            dato = dato + 1;
        }
    }
 
    for (int i = 0; i < matriz.length; i++) {
        for (int j = 0; j < matriz[i].length; j++) {
            System.out.print(matriz[i][j] + "\t");
        }
        System.out.println();
    }
}

Saludos,
Billy Joel
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar