Embed presentation
Download to read offline
![import java.util.Scanner;
class ArrayBidimension {
public static void main(String[]args){
Scanner scanner = new Scanner(System.in);
int[][] x = new int[][] {
{1, 20, 50, 100},
{2000, 7, 11, 21},
{30, 40, 200, 300},
{5, 10, 15, 90},
{15,25,50,100} ,
{2000,3000,10,20}
}, {
{1, 20, 50, 100},
{2000, 7, 11, 21}
}
};
//Escribir el segundo grid
for (int b = 0; b < x[1].length; b++) {
for (int y = 0; y < x[1][b].length; y++) {
System.out.print(x[1][b][y] + " ");
}
System.out.println();
}
scanner.close();
}
}](https://image.slidesharecdn.com/efnsjdnfsuies-160314160428/85/Efnsjdnfsuies-1-320.jpg)
This program declares a 2D array called x with 6 subarrays of 4 integer elements each. It then prints the elements of the 2nd subarray (index 1) using nested for loops to access each element. The outer loop iterates through the columns, and the inner loop iterates through the rows of the 2nd subarray to print each element and value separated by a space, with a new line after each column.
![import java.util.Scanner;
class ArrayBidimension {
public static void main(String[]args){
Scanner scanner = new Scanner(System.in);
int[][] x = new int[][] {
{1, 20, 50, 100},
{2000, 7, 11, 21},
{30, 40, 200, 300},
{5, 10, 15, 90},
{15,25,50,100} ,
{2000,3000,10,20}
}, {
{1, 20, 50, 100},
{2000, 7, 11, 21}
}
};
//Escribir el segundo grid
for (int b = 0; b < x[1].length; b++) {
for (int y = 0; y < x[1][b].length; y++) {
System.out.print(x[1][b][y] + " ");
}
System.out.println();
}
scanner.close();
}
}](https://image.slidesharecdn.com/efnsjdnfsuies-160314160428/85/Efnsjdnfsuies-1-320.jpg)