-8

How can I make this output in Java in a for-loop? How can I make every line less "*" ?

Input:
enter number: 6

Java output:

******
*****
****
***
**
*
Jordi Castilla
  • 24,953
  • 6
  • 58
  • 97
Michael
  • 195
  • 1
  • 8

2 Answers2

3

This seems a homework assignment, and it's nice to you to achieve this little goals to correct programming learning. As we're not here to make your homework, here you have few steps to guide you through:

  • Define a Scanner to ask user's input
  • Use Scanner to put user's input into a variable
  • Use this variable in a inverted for-loop (with loopCounter--)

    for (int loopCounter = userInputVariable; loopCounter > 0; loopCounter --) 
    
  • To repeat the * use:

    • StringUtils String repeated = StringUtils.repeat("*", loopCounter); or
    • for loop to repeat the char

      for (int innerLoopCounter = 0; innerLoopCounter < loopCounter; innerLoopCounter ++) 
      
Community
  • 1
  • 1
Jordi Castilla
  • 24,953
  • 6
  • 58
  • 97
0

Something like this. Please bear in mind that I don't know java.

for (int i = input; i > 0; i--) {
    System.out.println(StringUtils.repeat("*", i));
}
Jordi Castilla
  • 24,953
  • 6
  • 58
  • 97
Rob
  • 4,653
  • 4
  • 23
  • 40