钻石应该是这样的:
*
* *
* *
* *
*
我想使用简单的 for 循环,有人可以帮忙吗?我试过一颗完整的钻石:
void main() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("ENTER THE HEIGHT ");
int ht = Integer.parseInt(br.readLine());
int ht2 = (int) Math.floor(ht / 2);
ht = (int) Math.ceil(ht / 2);
for (int ht3 = ht - 1; ht3 >= 0; ht3--) {
for (int i = 1; i <= ht3; i++)
System.out.print(" ");
for (int j = 1; j <= ht - ht3; j++)
System.out.print("* ");
System.out.println();
}
for (int ht3 = 1; ht3 <= ht2; ht3++) {
for (int i = 1; i <= ht3; i++)
System.out.print(" ");
for (int j = ht2 - ht3; j >= 1; j--)
System.out.print("* ");
System.out.println();
}
}