Write a program IN JAVA to enter numbers in a 2-D array with n rows and m columns and print it in a matrix format.
no gibberish pls as this is URGENT!
Answers
Answered by
0
Answer:
Program:-
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int m,n;
System.out.println("Enter the number of rows:");
n=in.nextInt();
System.out.println("Enter the number of columns");
m=in.nextInt();
int a[][]=new int[n][m];
System.out.println("Enter the elements of the array:");
for(int i=0;i<n;i++)//n number of rows
{
for(int j=0;j<m;j++)//m number of columns
{
a[i][j]=in.nextInt();
}
}
System.out.println("The given array in matrix form:");
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
System.out.print(a[i][j]+ " ");
}
System.out.println();
}
}
}
Attachments:
Similar questions