2D array using java


class JavaArr
{
public static void main(String []ar)
{
int [][]a=new int [5][5];
int k;

for(int i=0;i<5;i++)
{
k=1;
for(int j=0;j<5;j++)
{
a[i][j]=k++;
}
}

System.out.println("Values in the array are :");

for(int i=0;i<5;i++)
{
for(int j=0;j<5;j++)
{
System.out.print("   "+a[i][j]);
}
System.out.println();
}

}
}


I/O : array is declared and value is passed through loop and values are displayed. type the program and run it , I hope its very simple to understand.

Comments

Popular posts from this blog

Pascal Triangle using 2D array

JAVA program to add two distance