发布网友 发布时间:2022-04-22 22:56
共1个回答
热心网友 时间:2023-10-08 00:50
public class Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入大于3奇数");
System.out.println("输入非数字退出");
while (sc.hasNextInt()) {
int i = sc.nextInt();
printInt(i, true);
}
sc.close();
}
/**
* @param i
* @param in true 表示 X实心 false 空心
*/
static void printInt(int i, boolean in) {
if (i < 3 || i % 2 == 0) return;
for (int j = 0; j < i; j++) {
for (int k = 0; k < i; k++) {
if (k == j || k == i - j - 1) {
if (in) {
System.out.print("*");
} else System.out.print(" ");
} else {
if (in) {
System.out.print(" ");
} else System.out.print("*");
}
}
System.out.println("");
}
}
}