Question: DESCRIPTION This program will output a right-triangle based on user specified height, triangleHeight, and symbol, triangleSymbol. The output will consist of triangleHeight rows. On each

DESCRIPTION

This program will output a right-triangle based on user specified height, triangleHeight, and symbol, triangleSymbol. The output will consist of triangleHeight rows. On each row of the output, there will be one additional symbol to make the triangle shape.

For example, if the triangleSymbol = "%" and triangleHeight = 5, the output should be:

Enter a symbol:

%

Enter triangle height:

5

%

% %

% % %

% % % %

% % % % %

One way to do this is to use a nested-loop. The outer loop can count through the total number of rows. The inner-loop can print out the correct number of symbols for the current row.

Starter code:-

import java.util.Scanner;

public class DrawRightTriangle { public static void main(String[] args) { //create Scanner for inputs and variables to store the triangle's height and symbol to print Scanner scnr = new Scanner(System.in); String triangleSymbol; int triangleHeight; System.out.println("Enter a symbol:"); triangleSymbol = scnr.next(); System.out.println("Enter triangle height:"); triangleHeight = scnr.nextInt(); System.out.println(); //blank line before triangle output // TODO // Draw right triangle } }

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!