Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Java-conversion Two Dimensional Array Program Using Nested For Loop

Related Tutorials


 
 

Share on Google+Share on Google+

Two Dimensional Array Program Using Nested For Loop

Advertisement
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 Using Nested For Loop 

     

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

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 25, 2008

Related Tutorials

Discuss: Two Dimensional Array Program Using Nested For Loop   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:3
roopendra kumar
March 19, 2012
display element of an array

i want to input the element of an array using BufferReader and print them.
roopendra kumar
March 19, 2012
addition of two matrix

input and display addition of two matrix using BufferReaderInputStream
eduado
December 11, 2012
all

i didnt understand all
DMCA.com