49. JAVA Program To Display 9 numbers in 3X3 matrix order.
How does this program work?
- This program is used to print the given 9 numbers into 3X3 structure.
Here is the code
//Programme to print 3x3 Matrix using java.
import java.util.Scanner;public class Matrix
{
public static void main(String args[])
{
int i,j,r,c;
System.out.println("Enter rows and columns:");
Scanner obj=new Scanner(System.in);
r=obj.nextInt();
c=obj.nextInt();
int a[][]=new int [r][c];
System.out.println("Enter elements of a matrix:");
for(i=0;i< r;i++)
{
for(j=0;j < c;j++)
{
a[i][j]=obj.nextInt();
}
}
System.out.println("The 3*3 Matrix is:");
for ( i=0;i< r;i++ )
{
for (j=0;j< c;j++)
{
System.out.print(a[i][j]+"\t");
if (j==(r-1))
System.out.println("\n");
}
}
}
}