//5. 定义一个二维数组,通过数组法输出一个九乘九(九行九列的方阵图)
//使对角线的值为"B",其他值为"A"
public class DoubleDimensionalArray{
public static void main(String[] args){
char[][] ch = new char[9][9];//定义九行九列的二维数组
/**
*以下是给二维数组赋值
*/
for (int i=0; i<ch.length; i++){
for (int j=0; j<ch[i].length; j++){
if (j == i){
ch[i][j] = 'B';
}
else {
ch[i][j] = 'A';
}
}
}
/**
*以下是遍历二维数组并打印
*/
for (int i=0; i<ch.length; i++){
for (int j=0; j<ch.length; j++){
System.out.print(ch[i][j] + " ");
}
System.out.println();
}
}
}
/*
*
程序在JCreator3.5中
//使对角线的值为"B",其他值为"A"
public class DoubleDimensionalArray{
public static void main(String[] args){
char[][] ch = new char[9][9];//定义九行九列的二维数组
/**
*以下是给二维数组赋值
*/
for (int i=0; i<ch.length; i++){
for (int j=0; j<ch[i].length; j++){
if (j == i){
ch[i][j] = 'B';
}
else {
ch[i][j] = 'A';
}
}
}
/**
*以下是遍历二维数组并打印
*/
for (int i=0; i<ch.length; i++){
for (int j=0; j<ch.length; j++){
System.out.print(ch[i][j] + " ");
}
System.out.println();
}
}
}
/*
*
程序在JCreator3.5中