【发布时间】:2020-05-23 16:21:08
【问题描述】:
我正在尝试使用 for 循环创建一个 5x5 矩阵,但我做不到,我一直在寻找它一天但我仍然无法弄清楚,所以我放弃并现在寻求帮助. 我需要一个像这样的矩阵;
1 0 0 0 0
2 3 0 0 0
4 5 6 0 0
7 8 9 10 0
11 12 13 14 15
我做了一个充满零的矩阵;
public class ExampleClass{
public static void main(String args[]) {
int[][] Example = new int [5][5];
for(int i=0;i<Example.length;i++){
for(int k=0;k<Example.length;k++)
System.out.print(Example[i][k]+" ");
System.out.println();
}
}
}
output:
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
【问题讨论】:
标签: java arrays loops for-loop