Tuesday, June 30, 2015

Multi Dimensional Array Program In Java







import java.util.Scanner;

public class Multidimen
{
public static void main(String[] args)
{
Scanner scn=new Scanner(System.in);
System.out.println("Type two no. for matrix");
int x=scn.nextInt();
int y=scn.nextInt();
int [][] a= new int [x][y];
int i, j, k=0;
for( i=0;i<x;i++)
   for(j=0;j<y;j++)
{
a[i][j]=k;
        k++;
}
for( i=0; i<x;i++)
{
for(j=0; j<y; j++)
{
System.out.print(a[i][j] +" ");
}
 }  
System.out.println();
}
}



Output :
Type two no. for matrix
3
4
0 1 2 3
4 5 6 7
8 9 10 11


0 comments:

Post a Comment