Two Dimensional Array Program

This page discusses - Two Dimensional Array Program

Two Dimensional Array Program Using Nested for loop


This is a simple Java array  program . In this session we will teach how to use of a two dimensional array. First of all we will define a class "Matrix". In this program we are going to make two dimensional array having three row and three columns. 

By using the multidimensional array we are going to make a matrix. For that we have to use a nested for loop. The for loop takes three parameters one is the initialization value, second, the place up to where the loop runs and the third one is the counter. Now declare one boolean type of variable found which will indicate whether the array has reached its limit or not.  Please go through this program properly so that you can understand what is happening in this program.

Here is the code of this Program

class Matrix{
 public static void main(String[] args){
  int[][] matrix = new int[3][3];
  for (int i =0; i < 3; i++){
 for (int j =0; j < 3; j++){
  boolean found = false;
  int i = 0;
  while (!found && i < 3){
 int j = 0;
 while (!found && j < 3){
  if (matrix[i][j==  2){
  found = true;
  System.out.println("The matrix is:");
  for (i=0; i < 3; i++){
 for (int j=0; j <3; j++){
  System.out.print(matrix[i][j" ");

Download this Example

Share on Google+Share on Google+

Two Dimensional Array Program

Posted on: April 17, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: Two Dimensional Array Program  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
January 11, 2012
2D array

how can be understand the program in 2D array per looping and per coding