DekGenius.com
JAVA
2d array java
char[][] array = new int[rows][columns];
Multidimensional Java Array
class multiDimensionalArray
{
public static void main(String args[])
{
int multiDimensional[][] = { {1,2,3},{4,5,6},{7,8,9} };
for (int i=0; i< 3 ; i++)
{
for (int j=0; j < 3 ; j++)
System.out.print(multiDimensional[i][j] + " ");
System.out.println();
}
}
}
2d array java
int[][] arr = new int[10][20];
arr[0][0] = 1;
display two dimensional array java
//this way u can print your array row by row
for (int i = 0; i < row; i++){
for (int j = 0; j < column; j++){
System.out.println(array[i][j]);
}
}
//this way u can print your array column by column
for (int i = 0; i < column; i++){
for (int j = 0; j < row; j++){
System.out.println(array[i][j]);
}
}
multidimensional arrays java
ships: [
{ locations: [0, 0, 0], hits: ["", "", ""] },
{ locations: [0, 0, 0], hits: ["", "", ""] },
{ locations: [0, 0, 0], hits: ["", "", ""] }
],
Java 2-dimensional Array
class MultidimensionalArray {
public static void main(String[] args) {
// create a 2d array
int[][] a = {
{1, 2, 3},
{4, 5, 6, 9},
{7},
};
// calculate the length of each row
System.out.println("Length of row 1: " + a[0].length);
System.out.println("Length of row 2: " + a[1].length);
System.out.println("Length of row 3: " + a[2].length);
}
}
multidimensional arrays java
ships: [
{ locations: [0, 0, 0], hits: ["", "", ""] },
{ locations: [0, 0, 0], hits: ["", "", ""] },
{ locations: [0, 0, 0], hits: ["", "", ""] }
],
© 2022 Copyright:
DekGenius.com