解题思路

import java.util.Scanner;

public class Main{
    
    public static void main(String[] args){
        Scanner sin = new Scanner(System.in);
        int n = sin.nextInt();
        int m = sin.nextInt();
        int[] nm = new int[n*m];
        int i = 0;
        while(sin.hasNext()){
            nm[i++] = sin.nextInt();
        }
        
        // 
        int[][] nms = new int[n][m];
        int t = 0;
        for(int in =0;in<n;in++){
            for(int im = 0;im<m;im++){
                nms[in][im] = nm[t++]; 
            }
        }
        // 调用方法
        print(nms,n,m);
    }
    
    public static void print(int[][] nms,int n,int m){
        int t = 0;
        for(int in =0;in<n;in++){
            for(int im = 0;im<m;im++){
                System.out.print(nms[in][im] + " ");
            }
            System.out.println(" ");
        }
    }
}