Two Dimensional Array Program

This is very simple program of Java. In this lesson we will learn how to display arrange form of two dimensional array program.

Two Dimensional Array Program

This is very simple program of Java. In this lesson we will learn how to display arrange form of two dimensional array program.

Two Dimensional Array Program

Two Dimensional Array Program 

     

This is very simple program of Java. In this lesson we will learn how to display arrange form of two dimensional array program. Firstly, we have to define class "TwoDimensional ". We are going to make a integer for array declaration Two dimensional array program. We are going to using for loop for performing the five rows and five columns.

Now applying the for loop and define an integer ' i' and it should be either less then" 5" or "j" in another for loop. Here in the second loop "j" the number of times to print. So the output will be display on the command prompt by using the println() method.  

Here is the code of this program

class  TwoDimensionalArray
{
  public static void main(String[] args
  {
  int TwoDarray[][]=new int[0][0];
  int k=0;
  for (int i=0; i<5; i++)
  {
  for(int j=0; j<=i; j++)
  {
  System.out.print(" "+ k);
  k++;
  }
  System.out.println(" ");
  }
  }
}

Download this Example