Question: Need in JAVA: Write a program that accepts an integer from the user and prints out a triangle with those many lines of *. The

Need in JAVA: Write a program that accepts an integer from the user and prints out a triangle with those many lines of *. The first line has one *, the second has 2 * and so on. Make sure your program conforms to the following requirements:

Accept the number of lines from the user (as an integer).

Check if the number of lines is positive. If it happens to be negative, print an error message and terminate the program.

If the number is positive, pass this number as a parameter to a method called printTriangle().

In the printTriangle()method use a loop to print the triangle of *.(10 points)

Enter the number of lines : 5

*

**

***

****

*****

*NOTE* that there is NO keyboard-input/screen-output specified in the methods themselves. This means you should NOT have any Print statements or Scanner usage inside these named methods. Any printing and/or keyboard input is done by main() in each exercise

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!