编写程序,建立并输出一个10*10的矩阵,该矩阵对角线元素为1,其余元素均为0。输出该数组。
package rwwr;
public class Arrayexam3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int a[][]=new int[10][10];
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
a[i][j]=0;
if(i==j||i+j==9){
a[i][j]=1;
}
}
}
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
}