36 Program on jagged array in Java

Code:

import java.util.Scanner;
class Aray
{
public static void main( String args[] )
{
Scanner scan = new Scanner( System.in );
int arr[][] = new int[2][];

int i,j;

arr[0]=new int[3];
arr[1]=new int[2];


for( i=0;i<arr.length;i++ )
{
for( j=0;j<arr[i].length;j++ )
{
System.out.print("Enter for a["+i+"] b["+j+"] =");
arr[i][j]=scan.nextInt();
}
System.out.println(" ");
}

System.out.println("Displaying Array=");

for( i=0;i<arr.length;i++ )
{
for( j=0;j<arr[i].length;j++ )
{
System.out.println("a["+i+"] b["+j+"] ="+  arr[i][j]);

}
}

}
}


Output:  

Previous
Next Post »