我正在尝试使用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
I would do this with another variable, let's say it's called
c
:或者,如果您还想要适当的间距:
输出: