gpt4 book ai didi

java - 在java中打印对角三角形

转载 作者:行者123 更新时间:2023-12-02 06:29:08 25 4
gpt4 key购买 nike

我需要打印出一个如下所示的三角形:

*
**
***
****

我现在拥有的代码

    for(line = 0; line < size; line++){
for(count = 0; count < line; count++){
System.out.print("*");
for(space = 0; space < line; space++)
System.out.print(" ");
}
System.out.println();
}

我明白了

* 
**
***
****
*****
******

最佳答案

for(line = 0; line < size; line++){
for(space = 0; space < line; ++space)
System.out.print(" ");
for(count = 0; count < line; count++)
System.out.print("*");
System.out.println();
}

关于java - 在java中打印对角三角形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20233898/

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