满意答案

rifvjjj
2015.08.08

采纳率:59% 等级:9
已帮助:464人
java中自定义矩阵:
public static void main(String[] args) {
// TODO Auto-generated method stub
int n= 5;//长度
int array_int[][] = new int[n][n];
//初始化
for(int i=0;i
for(int j=0;j
if(i==0){
if(j%2==0){
array_int[i][j] = (j+1)*(j+1);
}
else{
array_int[i][j] = array_int[i][j-1]+1;
}
}
else if(j==0){
if(i%2==1){
array_int[i][j] = (i+1)*(i+1);
}
else {
array_int[i][j] = array_int[i-1][j]+1;
}
}
else{
if(i
if(j%2==0){
array_int[i][j] = array_int[0][j]-i ;
}
else{
array_int[i][j] = array_int[0][j]+i ;
}
}
else{
if(i%2==0){
array_int[i][j] = array_int[i][0]+j ;
}
else{
array_int[i][j] = array_int[i][0]-j ;
}
}
}
//System.out.println(i+" "+j+":"+array_int[i][j] );
}
}
for(int i=0;i
for(int j=0;j
System.out.print(array_int[i][j]+ " " );
}
System.out.println();
}
}
当等于5时的运行结果:
1 2 9 10 25
4 3 8 11 24
5 6 7 12 23
16 15 14 13 22
17 18 19 20 21
00分享举报
这篇博客介绍了如何在Java中创建并初始化一个自定义的二维矩阵,通过一个示例展示了如何填充矩阵,并提供了矩阵的输出方法。矩阵的填充规则根据行和列的索引进行计算,最后给出了当矩阵长度为5时的运行结果。

798

被折叠的 条评论
为什么被折叠?



