I suppose that there exists a way to know the length of each dimension in multidimensional arrays. I have the following code and in the for
conditional I would like to change the condition so that it works for every array.
import javax.swing.JOptionPane;
public class Arrays_bidimensionales {
public static void main(String[] args) {
int[][] matriz1 = new int[4][5];
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 5; j++) {
matriz1[i][j] = Integer.parseInt(JOptionPane.showInputDialog("Introduce el valor para la posiciĆ³n" + i + "." + j));
System.out.print(" " + matriz1[i][j] + " ");
}
System.out.println();
}
}
}
I have tried with matriz1.length
but only seems to work with arrays with a unique dimension.
Arrays in Java have a
length
property, so you could dynamically query an array's length, even if it's a multidimensional jagged array: