Code:
public class Test6 {
public static void main(String[] args) {
PrintX (10);
}
/ *
2. The method defined PrintX, parameters (int m), the return value without
3.printX method, a for loop, initializes the variable x = 1, if x <= m into the circulation, step ++ expression X
4.for inner loop, then defining a set of nested for-loop, initializes the variable y = 1, if y <= m into the circulation, the stepping ++ expression Y
5. The interior of the inner loop, x == y is determined or x + y == 1 + m, print "O", otherwise the print "*"
* /
public static void PrintX (int m) {
for (int x = 1; x <= m; x++) {//循环7行
for (int y = 1; y <= m; y++) {//循环7列
if (x == y || x + y == m + 1) {//对角线打印O
System.out.print("O");
} else {
System.out.print("*");//其他位置打印.
}
}
System.out.println();//换行
}
}
}