logo
Java Two Dimensional Array
Two dimensional arrays (2D arrays):
A two dimensional array represents several rows and columns of data.
Java Images
Syntax for creating 2D array:

Case 1: We can declare a two dimensional array and directly store elements at the time of it declaration, as:
Example: int marks[ ][ ] = {{5, 6, 7, 7, 8}, {8, 9, 9, 9, 3}, {4, 5, 6, 8, 7}};

int marks[ ][ ] = new int[3][3];
Two dimensional arrays program
import java.util.*; 
class Test
{ public static void main(String[] args) 
{ 
int[][] a=new int[2][2]; 
Scanner s=new Scanner(System.in); 
for (int i=0;i	for(int j=0;j System.out.println("enter ith "+(i+1)+" and j "+(j+1)+" value"); 
a[i][j]=s.nextInt(); 
} 
} 
for (int i=0;i	for(int j=0;j System.out.println("ith "+(i+1)+" and j "+(j+1)+" value is"+a[i][j]); 
} 
} 
} 
} 
Output :
enter ith 1 and j 1 value 10 enter ith 1 and j 2 value 20 enter ith 2 and j 1 value 60 enter ith 2 and j 2 value 90 ith 1 and j 1 value is10 ith 1 and j 2 value is20 ith 2 and j 1 value is60 ith 2 and j 2 value is90