Write a Java Program to Accept & Print Matrix.
In this tutorial we are going to learn how we can accept matrix from user and print in matrix format.
Program :- (Java Program to Accept & Print Matrix )
import java.util.*;
public class PrintMatrix{
public static void main(String[] args){
System.out.println("Enter limit of Matrix ");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
System.out.println("Enter the Values ");
int[][] arr=new int[10][20];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
arr[i][j]=sc.nextInt();
}
}
System.out.println("Enter Matrix is ");
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
System.out.print(arr[i][j]+"\t");
if(j==(n-1))
{
System.out.println();
}
}
}
}
}
Output :-
Comments
Post a Comment