Pages

Friday, 13 December 2019

Program to illustrate Two Dimensional Array

Program to illustrate Two Dimensional Array 

import java.util.Scanner;
class rkar2
 {
  public static void main(String x[])
  {
   int m,n;
   Scanner s=new Scanner(System.in);
   System.out.println("Enter Number of Rows(m) in Array  :");
   m=s.nextInt();
   System.out.println("Enter Number of Columns(n) in Array  :");
   n=s.nextInt();
   int[][] a;//declaration of array
   a=new int[m][n]; // Creation of array with given size
   System.out.println("Enter "+m+"Rows and "+n+" Columns "+m*n+" Elements");
   for(int i=0;i<m;i++)
    {
     for(int j=0;j<n;j++)
     {
     a[i][j]=s.nextInt();
     }
    }
   System.out.println("\n Array elements :");
   for(int i=0;i<m;i++)
    {
     for(int j=0;j<n;j++)
     {
     System.out.print(a[i][j]+"\t");
     }
     System.out.println("\n");
    }
   for(int i=0;i<m;i++)
    {
     for(int j=0;j<n;j++)
     {
      System.out.printf("\n ADDRESS=%h ---- ARRAY=a[%d][%d] DATA=%d\n",a,i,j,a[i][j]);
     } 
   }
  }
}

output:


No comments:

Post a Comment

Constructors & Destructors in c++

  Constructors :  A Constructor is a special member function, which is used to initialize the objects of its class. The Constructor is invok...