Question: Figure 12-26 shows two typical executions of a program that displays a triangle. Create this program by prompting the user for a number of lines

Figure 12-26 shows two typical executions of a program that displays a triangle. Create this program by prompting the user for a number of lines to display. The first row of the output contains the number of spaces that equals the number of lines that will eventually display. Pass the final number of lines, the current line number, the spaces to display, and the number of letters to display to a recursive method. The base case occurs when the current line equals the total number of lines to display. If the total number of lines has not yet been displayed, reduce the number of spaces, increase the number of letters, increase the current line number, and call the method again. Save the program as TriangleRecursive.java.


Data from in Figure 12-26

Figure 12-26 Two typical executions of the TriangleRecursive program How many lines

Figure 12-26 Two typical executions of the TriangleRecursive program How many lines to display? >> 3 How many lines to display? >> 7 T T TTT TTT TTTTT TTTTT TTTTTTT TTTTTT

Step by Step Solution

3.45 Rating (155 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

import javautilScanner class TriangleRecursive public stati... View full answer

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