Write a program that asks the user to enter the size of a triangle (an integer f
ID: 3632082 • Letter: W
Question
Write a program that asks the user to enter the size of a triangle (an integer from 1 to 50). Display the triangle by writing lines of asterisks. The first line will have one asterisk, the next will have two, and so on, with each line having one more asterisk than the previous line, up to the number entered by the user. On the next line write one fewer asterisk and continue by decreasing the number of asterisks by 1 for each successive line until only one asterisk is displayed. (HINT : USE NESTED for loops; the outside loop controls the number of lines to write and the inside loop controls the number of asterisks to display on a line)for example, if the user enters the number 3
output will be
*
**
***
**
*
Explanation / Answer
import java.util.*; public class drawTriangle{ public static void main(String[] args) {int i,j,n; Scanner in= new Scanner(System.in); System.out.println("Enter size of triangle:"); n=in.nextInt(); for(i=0;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.