Basic example using Two Dimensional Array in Java


Here is the simple program for printing basic example using Tow Dimensional Array in Java.

Source Code

import java.io.*;
import java.util.Scanner;
class arrayss
{
  public static void main(String args[])
  {
    int [][]a =new int[100][100];
    int [][]b =new int[100][100];
    int [][]c =new int[100][100];
    int i,j,n,m;
    System.out.print("\nEnter The row and cols : \n ");
    Scanner in =new Scanner(System.in);
    n=in.nextInt();
    m=in.nextInt();
    System.out.print("\nEnter The Value Of A Matrix  \n ");
    for(i=0;i<n;i++)
    {
      for(j=0;j<m;j++)
      {
        System.out.print("\na["+i+"]["+j+"]: ");
        a[i][j]=in.nextInt();
      }
    }
    System.out.print("\nEnter The Value Of B Matrix: \n ");
    for(i=0;i<n;i++)
    {
      for(j=0;j<m;j++)
      {
        System.out.print("\nb["+i+"]["+j+"]: ");
        b[i][j]=in.nextInt();
      }
    }
    System.out.print("\nResult Matrix: \n ");
    for(i=0;i<n;i++)
    {
      for(j=0;j<m;j++)
      {
        c[i][j]=a[i][j]+b[i][j];
        System.out.print("\t"+c[i][j]);
      }
      System.out.print("\n");
    }
  }
}
To download raw file Click Here

Output

Enter The row and cols :
 2
 2
Enter The Value Of A Matrix
a[0][0]: 1
a[0][1]: 1
a[1][0]: 1
a[1][1]: 1
Enter The Value Of B Matrix:
b[0][0]: 1
b[0][1]: 1
b[1][0]: 1
b[1][1]: 1
Result Matrix:
        2       2
        2       2


Learn All in Tamil © Designed & Developed By Tutor Joes