Live Code!

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

What would the program do if the user asked for a negative number of stars per line?

Answer:

Each line would consist of nothing but the end of line character that System.out.println() prints. The inner loop would not execute even once.

Live Code!

For your amusement and entertainment here is a JavaScript version of the program:

How Many Rows: How Many Stars:

QUESTION 23:

On a clear evening, out in the country, far from city lights, about 6,000 stars are visible. Enter values so the program prints that many stars.

(If you ask for for than 50 stars per line, the excess stars for each line will print on a second line.)