Printing a Row of Stars

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Answer:

With a loop that counts 1 to numStars and prints a * for each iteration.

Printing a Row of Stars

Here is the answer to the little problem. The parts of the program that don't affect it have been (temporarily) cleared away.


    // collect input data from user
    System.out.print( "How many Stars per Row? " );
    numStars = scan.nextInt() ;


      int star = ;
      while ( star <=  )
      {
        System.out.print("*");
        
      }

      System.out.println();

QUESTION 21:

Need I ask? Fill in the blanks so that numStars stars are printed.