


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A problem from the book 'java - an introduction to problem solving & programming' by walter savitch. The problem asks to write a java program that prints a triangle of asterisks based on user input. The triangle should have a number of lines equal to the user input, with each line having one more asterisk than the previous line. A variation of the problem asks to print a triangle with a given height, where the outside loop controls the number of lines and the inside loop controls the number of asterisks on each line. For example, if the height is 5, the output would be: * * * * * * * * * * * * * * * * * * * * * * * * *
Typology: Study notes
1 / 4
This page cannot be seen from the preview
Don't miss anything!



Write a program that asks the user to enter the size of atriangle to print out (an integer from 1 to 50), then printthe triangle by printing a series of lines consisting ofasterisks. The first line will have one asterisk, the nexttwo, and so on, with each line having one more asteriskthan the previous line, up to the number entered by theuser. On the next line print one less asterisk andcontinue by decreasing the number of asterisks by 1 foreach successive line until only one asterisk is printed. Hint
: Use nested
for
loops; the outside loop controls the
number of lines to print, and the inside loop controls thenumber of asterisks to print on a line. For example, if theuser enters
, the output would be (next page)
-^
height
height
is
, then print the
following.