Triangle Application

Write an application called Triangle that prompts the user to enter a number. If the number is less than 0, print out an error message. If it is not, print a triangle, using the star character ("*").

Your program will:

  1. At first just print out that number of stars (using a "*"), all on one line.
  2. Then, after that is working, change it to print out a triangle of stars with the point of the triangle having the number of stars that was entered.

Here is a sample dialog from running the program 4 times, first for just the line of stars:

Please enter a number: 3

***

Please enter a number: 16

****************

Please enter a number: -3

*** That is not a valid entry. ***

Please enter a number: 2

**

Note: the example dialogs (above and below) show running the program 4 different times.

The code to print the line of stars should be in a method called printStarLine(); here is the signature to use:

public static void printStarLine(int numStars)

After a printing a single line of stars is working, then add the triangle part: Write another method called printTriangle() that takes a single integer argument and uses your printStarLine() function to print the side-ways triangle, with the point the number of stars the user types in. This should also be static.

Then change your main() to use your printTriangle() function to print the triangle.

Here is a sample dialog from running the completed program 4 times:

Please enter a number: 3

*
**
***
**
*

Please enter a number: 16

*
**
***
****
*****
******
*******
********
*********
**********
***********
************
*************
**************
***************
****************
***************
**************
*************
************
***********
**********
*********
********
*******
******
*****
****
***
**
*

Please enter a number: -3

*** That is not a valid entry. ***

Please enter a number: 2

*
**
*

Optional: Write the program such that the string used to draw the triangle is passed in as an argument, hardcoded in main. You should still have a printStarLine() method, with the same signature specified above. How does this change your design from that which is given? Can you then update your program to take the string as a command-line argument? And use a star ("*") if no argument is specified?