Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Write a java program to accept 3X3 matrix from the user and print the same.

import java.io.*;
public class Demo_2D {

public static void main(String args[])


{
try
{
int a[][]=new int[3][3];
int i,j;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter 3X3 Matrix:");

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
a[i][j]=Integer.parseInt(br.readLine());
}
System.out.println("");
}

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
System.out.print("\t"+a[i][j]);
}
System.out.println("");
}

}catch(Exception ex){ex.printStackTrace();}
}
}

You might also like