-1

Hi im new here and fairly new to java in school ive got a program here that ive got working its just now printing the way it should hers the program

import java.util.*;
public class stars
{
   public static void main(String args[]){  
    Scanner keyboard = new Scanner(System.in);
    System.out.print("Enter the starting Value");

    for( int star=keyboard.nextInt(); star>=1; star--)
    { for( int starTwo=star;starTwo>=1; starTwo--)
        {
      System.out.println("*");
    }
    }

    }    
}

it prints right now in a straight column going down it has the correct number of "*" just in the wrong format. I need it so row 7 has 7 , row 6 has 6 row 5 has 5 ect. all the way to 1.

Thank you in advance.

1 Answers1

1

Your question is a duplicate Please go through this How can I print to the same line?

Please understand System.out.println means to print to a new line.

You need to use System.out.print("*");

for (int star = keyboard.nextInt(); star >= 1; star--) {
    System.out.println("");
    for (int starTwo = star; starTwo >= 1; starTwo--) {
        System.out.print("*");
    }
}

Example

    for (int star = 7; star >= 1; star--) {
    System.out.println("");
    for (int starTwo = star; starTwo >= 1; starTwo--) {
        System.out.print("*");
    }
}

prints

*******    
******
*****
****
***
**
*
Community
  • 1
  • 1
Acewin
  • 1,657
  • 4
  • 17
  • 36