Accessing of two dimensional array

Before access to multidimensional array java, you must read about what is a two-dimensional array. In Java two – dimensional arrays are arrays of arrays, so arrayName[x][y] is an array x(size) of rows in arrays and y(size) of columns in the array. So, if you want to access any value from the array then you must specify the index of row and column. These are also known as multidimensional array java.

class ArrayExample
{
  public static void main(String args[])
  {
    //declaration two dimensional array with initialization
    int number [][]={ {11,22,33}, {44,55,66}, {77,88,99} };
    //print the value of two dimensional array
    for(int i = 0; i < 3; i++)
    {
      for(int j=0;j<3;j++)
        {
          System.out.println("Index of number is i = "+i+ " j =  "+ j+ " and Element is = "+ 
          number [i][j]+" ");
        }
        System.out.println();
    }
  }
}

Output:
Index of number is i = 0 j =  0 and Element is = 11
Index of number is i = 0 j =  1 and Element is = 22
Index of number is i = 0 j =  2 and Element is = 33
 
Index of number is i = 1 j =  0 and Element is = 44
Index of number is i = 1 j =  1 and Element is = 55
Index of number is i = 1 j =  2 and Element is = 66
 
Index of number is i = 2 j =  0 and Element is = 77
Index of number is i = 2 j =  1 and Element is = 88
Index of number is i = 2 j =  2 and Element is = 99
 

multidimensional array java

1. Quiz, Read the below code and do answer.

public class ArrayExample
{
  public static void main(String args[])
  {
      int number [][]={ {11,22,33}, {44,55,66}, {77,88,99} };
      System.out.println(number[1][0]);
  }
}

Click on anyone to know the answer.

2. Quiz, Read the below code and do answer.

public class ArrayExample
{
  public static void main(String args[])
  {
      int number [][]={
              	        {11,22,33}, 
                        {44,55,66}, 
                        {77,88,99} 
                      };
      int[] array = number[0];
      for(int i = 0; i < array.length; i++)
          System.out.println(array[i]);
  }
}

 

Click on anyone to know the answer.

3. Quiz, Read the below code and do answer.

public class ArrayExample
{
  public static void main(String args[])
  {
      int number [][]={
              			{11,22,33}, 
                        {44,55,66}, 
                        {77,88,99} 
                      };
      int[] array = number[2];
      for(int i = 0; i < array.length; i++)
          System.out.println(array[i]);
  }
}

Click on anyone to know the answer.

4 thoughts on “Accessing of two dimensional array”

  1. Amazing post! We’re currently linking to this great article on our website.
    Keep up the great writing.
    Best regards,
    Lunding Duke

    Reply

Leave a Comment