[code]import java.util.Scanner;public class TestMultiArray {public static void main(String[] args) {System.out.print(\"请输入二维数组行数:\");Scanner x = new Scanner(System.in);int hang = x.nextInt();int a[] = new int[hang];System.out.print(\"请输入每行的列数:\");Scanner y = new Scanner(System.in);for (int i = 0; i < hang; i++) {int lie = y.nextInt();a[i] = lie;}int b [][] = new int[hang][];for (int i = 0, k = 1; i < hang; i++, k++) {System.out.print(\"请输入第\" + k + \"行的元素:\");b [i] = new int [a[i]];Scanner z = new Scanner(System.in);for (int j = 0; j < a[i]; j++) {b [i][j] = z.nextInt();}}System.out.println();System.out.println(\"输入的二维数组为:\");for (int i = 0; i < hang; i++) {for (int j = 0; j < a[i]; j++) {System.out.print(b[i][j]+\" \");}System.out.println();}}}
结果展示: