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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started