1 package com.wh.array; 2 3 import java.util.Arrays; 4 import java.util.Scanner; 5 6 public class Demo { 7 8 public static void main(String[] args) { 9 Scanner sc=new Scanner(System.in); 10 int m,n; 11 System.out.println("m"); 12 m=sc.nextInt(); 13 System.out.println("n"); 14 n=sc.nextInt(); 15 int[][] arr=new int[m][n]; 16 for (int i = 0; i < m; i++) { 17 for (int j = 0; j <n; j++) { 18 arr[i][j]=(int)(Math.random()*100); 19 } 20 } 21 for(int i=0;i<m;i++){ 22 System.out.println(Arrays.toString(arr[i])); 23 } 24 } 25 }
运行结果 m 3 n 7 [82, 32, 78, 36, 96, 32, 65] [24, 42, 6, 81, 99, 0, 31] [70, 56, 37, 5, 86, 94, 25]