Java - Matriz

 
Vista:
Imágen de perfil de Diego

Matriz

Publicado por Diego (23 intervenciones) el 21/03/2014 20:06:31
una pregunta como puedo hacer para que en consola me muestre la matriz de esta forma

|0000|
|00 |
|0 |
lo que pasa que ami me la muestra asi les agradeseria mucho su ayuda
|0
0
|0
0
|0
0
|0
0
|
|0
0
|0
0
|
|

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class TestMatriz {
 
    public static void main(String[] args) {
        int matriz[][] = new int[3][];
        matriz[0] = new int[4];
        matriz[1] = new int[2];
        matriz[2] = new int[0];
 
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < matriz[i].length; j++) {
                System.out.print("|");
                System.out.println(matriz[0][1]);
                System.out.println(matriz[i][j]);
                if (j != matriz[i].length - 1) {
                    System.out.print("\t");
                }
            }
 
            System.out.println("|");
        }
    }
}
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

Matriz

Publicado por Carlos (35 intervenciones) el 22/03/2014 10:01:16
Esta es la solucion:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public static void main(String[] args) {
int matriz[][] = new int[3][];
matriz[0] = new int[4];
matriz[1] = new int[2];
matriz[2] = new int[1];
String CAD="";
for (int i = 0; i < 3; i++) {
      CAD=CAD +"|";
for (int j = 0; j < matriz[i].length; j++) {
       CAD=CAD+matriz[i][j];
}
 CAD=CAD +"|";
System.out.println(CAD);
CAD="";
}
}

Saludos.
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