如何创建基于用户输入创建星型金字塔的循环。

huangapple go评论62阅读模式
英文:

how to create loops in which create a star pyramid based on user input

问题

Sure, here's the translation of the code you provided:

java编写一个应用程序将会要求用户输入一个正整数根据用户的输入您的程序必须使用循环来创建一系列星星图案每一行的星星数量都要少一个

输入

    5

输出

    *****
    ****
    ***
    **
    *
英文:

(java) Write an application that will ask the user to enter a positive integer. Based on the user input, your program must use a loop(s) to create a pattern of stars, each subsequent row must have one less star.

input:

5

output

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

答案1

得分: 1

void printStars(int num){
for(int i=num; i>0; --i){
for(int j=0; j<i; ++j){
System.out.println("*");
}
System.out.println("");
}
}

The above code should help.

英文:
void printStars(int num){
    for(int i=num;i&gt;0;--i){
        for(int j=0;j&lt;i;++j){
            System.out.println(&quot;*&quot;);
        }
        System.out.println(&quot;&quot;);
    }
}

The above code should help.

huangapple
  • 本文由 发表于 2020年10月8日 21:33:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/64263640.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定