I am making a program to guide me through the basic fundamentals of multidimensional arrays. The program is very simple and works well, well, half well. I have the following code:
public class guia {
public static void main(String[] args) {
int[][] numeros; //declaración array con dos dimensiones
int f, c; //para recorrer el array. F = filas; C = columnas
numeros = new int[2][3]; // Tendrá 2 filas y 3 columnas
for (f = 0; f < numeros.length; f++) { //primero recorre las filas
for (c = 0; c < numeros[f].length; c++) { //despues recorre cada columna que haya en esa fila
numeros [f][c]=0; // rellena todo el array con 0
}
}
//Muestra el array
for (f = 0; f < numeros.length; f++) {
for (c = 0; c < numeros[f].length; c++) {
System.out.println(numeros[f][c] + " ");
}
System.out.println("\n");
}
}
The statement
println()
is used to print each parameter passed to it on one line. Change that statement inside the two nested loops toSystem.out.print()
I have made a modification so that it is done as you want:
As a result, return this: