Description
Create a method printUpsideDownTriangle(int width)
that takes a width
as an argument and prints an upside down triangle whose base is width
wide.
Example
class UpsideDownTrianglePrinter { public static void main(String[] args) { printUpsideDownTriangle(5); System.out.println(); //print a blank line. printUpsideDownTriangle(3); } }
When executed, the above program would print:
***** **** *** ** * *** ** *
Submission
Submit the .java file that contains your printUpsideDownTriangle(int width)
method. You may also include a main()
method but this will not be graded.
Hints
- Think of the triangle as a table with rows and columns. How many
*
s are printed at each row? - Use a flowchart to design your algorithm first. You may even use visual logic if you please and then translate it to a Java program.
- Notice what is to the left of the asterisks.
' '
or" "
may be used as spaces.
Extra Credit
- (2 points) Accept an additional parameter that dictates the character to use to draw the triangle, e.g.,
upsideDownTriangle(int width, char character)
. Use this character to draw the triangle.
This material was created by Raffi Khatchadourian and published freely under a Creative Commons Attribution 4.0 license.