初学者请问:用JAVA怎么写二维数组的输入
答案:1 悬赏:10 手机版
解决时间 2021-04-15 00:22
- 提问者网友:箛茗
- 2021-04-13 23:30
初学者请问:用JAVA怎么写二维数组的输入
最佳答案
- 五星知识达人网友:行雁书
- 2021-04-14 01:05
import java.util.Scanner;
class Test {
public static int[][] a = new int[20][20];
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Input m and n:");
int m = in.nextInt(); //行数
int n = in.nextInt(); //列数
for (int i = 0; i < m; i ++) {
for (int j = 0; j < n; j ++) {
a[i][j] = in.nextInt();
}
}
System.out.println("Output:");
for (int i = 0; i < m; i ++) {
for (int j = 0; j < n; j ++) {
System.out.print(a[i][j] + " ");
}
System.out.println();
}
}
}运行结果:
class Test {
public static int[][] a = new int[20][20];
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Input m and n:");
int m = in.nextInt(); //行数
int n = in.nextInt(); //列数
for (int i = 0; i < m; i ++) {
for (int j = 0; j < n; j ++) {
a[i][j] = in.nextInt();
}
}
System.out.println("Output:");
for (int i = 0; i < m; i ++) {
for (int j = 0; j < n; j ++) {
System.out.print(a[i][j] + " ");
}
System.out.println();
}
}
}运行结果:
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯