class Demo {
public static void main(String[] args) {
System.out.println(" 请输入一个正奇整数:");
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
if (a >= 0 && a % 2 == 1) {
for (int i = 1; i <= (a+1)/2; i++) {
int y = java.lang.Math.abs((a + 1) / 2 - i);
for (int b = 1; b <= y; b++) {
System.out.print(" ");
}
for (int c = 1; c <= (a - 2 * y); c++) {
System.out.print("*");
}
for (int d = 1; d <= y; d++) {
System.out.print(" ");
}
System.out.println();
}
}
}
}作者: D-Carl 时间: 2016-6-3 19:37
我这个之前是打印菱形◇的,大for循环里改成i <= a 就是打印菱形了