gpt4 book ai didi

java - 用三角力量打造三角力量?

转载 作者:行者123 更新时间:2023-12-01 13:43:15 24 4
gpt4 key购买 nike

我已经编写了一段代码,使用 for 循环创建完美的三角力。我如何使用更多的 for 循环来从这些三角力中创建三角力?

注意:“ROptionPane”与“JOptionPane”相同

public static void main(String[] args) {


String rowsWantedAsSt = ROptionPane.showInputDialog(null, "How big would you like the Diamond to be?",
"Diamond", ROptionPane.QUESTION_MESSAGE);

int rowsWanted = Integer.parseInt(rowsWantedAsSt);


//stars on the top row
int starsWanted = 1;
//spaces on the top row
int spacesWanted = (rowsWanted * 2) + 3;





for (int rows = 0; rows < rowsWanted; rows++) {
for (int spaces = 0; spaces < spacesWanted; spaces++) {
System.out.print(" ");
}
for (int stars = 0; stars < starsWanted; stars++) {
System.out.print("*");
}
System.out.println();
starsWanted += 2;
spacesWanted--;
}
starsWanted = 1;

spacesWanted = rowsWanted + 1;

for (int rows = 0; rows < rowsWanted; rows++) {
for (int spaces = 0; spaces < spacesWanted + 2; spaces++) {
System.out.print(" ");
}
for (int stars = 0; stars < starsWanted; stars++) {
System.out.print("*");
}

for (double spaces = 0; spaces < (spacesWanted * 2) - 3; spaces++) {
System.out.print(" ");
}
for (int stars = 0; stars < starsWanted; stars++) {
System.out.print("*");
}
System.out.println();
starsWanted += 2;
spacesWanted--;

}
}
}

最佳答案

Triforce 与创建Sierpinski triangle 的算法第一次迭代的结果相同。 。由 Triforce 组成的 Triforce 看起来像是该算法的第二次迭代。

Rosettacode.org 有两个不同的 Java implementations迭代生成 ASCII Sierpinski 三角形的函数;您可能想从这里开始。

关于java - 用三角力量打造三角力量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20527870/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com