Print array element in matrix form



CODE:
import java.util.*;
class Matrix
{
     public static void main(String args[])
     {
           int m,n,i,j;
           Scanner sc = new Scanner(System.in);
           System.out.print("Enter no of rows & columns :");
           m=sc.nextInt();
           n=sc.nextInt();
           int a[][]=new int[m][n];
           for(i=0;i<=m-1;i++)
           {
                for(j=0;j<=n-1;j++)
                {
                     System.out.print("enter a no:");
                     a[i][j]=sc.nextInt();
                }
           }
           for(i=0;i<=m-1;i++)
           {
                for(j=0;j<=n-1;j++)
                {
                     System.out.print(a[i][j]+"/t");
                }
                System.out.println();
           }
     }
}  
OUTPUT:   
    
          

No comments :

Post a Comment