Question: Objective: Triangle program - Create a method that takes an integer input n and outputs a triangle of the * character that is n in

Objective: Triangle program - Create a method that takes an integer input n and outputs a triangle of the * character that is n in length. In the main method prompt the user to enter a whole number and pass that number to your method.
Details: You are required to have a static method in this assignment in addition to the static main method. The static method should be a void method that takes a single integer variable, n, as its input. The static method then follows these steps (Note that I use indention to signify steps within a loop):
Open a file called "triangle.txt"
Set up a PrintWriter to output to triangle.txt (see lecture video for example)
Create a for loop that starts at i =0 and ends at i < n
Within the for loop create a second for loop that starts at j =0 and ends at j <(i +1)
This is called a nested loop. It is when you have a loop inside of another loop
Within the nested loop write "*" to the file using the .write() method in PrintWriter
Example: If my PrintWriter object is called fileWriter I would call: fileWriter.write("*");
After the nested loop ends, write "
" to the file using the .write() method in PrintWriter
After both loops and before your function returns call the .close() method in PrintWriter to guarantee everything is output to the file

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 Programming Questions!