版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/kimiszc/article/details/83536473
import java.util.Scanner;
public class Matrix{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Please enter the row number of matrix");
int row = in.nextInt();
System.out.println("Please enter the col number of matrix");
int col = in.nextInt();
System.out.println("Please enter the elements of matrix one by one, using enter to feed the matrix");
while(in.hasNext()){
int[][] matrix = new int[row][col];
for(int i = 0; i < row*col;i++){
matrix[i/col][i%col] = in.nextInt();
}
for(int i = 0; i < row; i++){
for(int j = 0; j < col; j++){
System.out.print(matrix[i][j]+" ");
}
System.out.println();
}
}
in.close();
}
}