Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Triangle Maker 9000! Objective: Write a program that takes in a positive number

ID: 3870345 • Letter: T

Question

Triangle Maker 9000!

Objective:

Write a program that takes in a positive number and draws a horizontal triangle of asterisks (*). The inputted number represents the size of the triangle, or in other words the number of asterisks at the peak. It starts out by increasing the number of asterisks at each line until it reaches the size of the triangle and then decreases the number of triangles at each line.

Example Dialog:

Welcome to Triangle Maker 9000! Enter the size of the triangle.

3

*

**

***

**

*

DONE!

i need it by Drjava please

Explanation / Answer

import java.util.Scanner;
class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.print("Welcome to Triangle Maker 9000! Enter the size of the triangle:");
// Get input
int n = sc.nextInt();
//print upper part of triangle
for(int i=0;i<n;i++){
for(int j=0;j<i;j++){
System.out.print('*');
}
System.out.println();
}
//print lower part of triangle
for(int i=n;i>0;i--){
for(int j=i;j>0;j--){
System.out.print('*');
}
System.out.println();
}
}
}

/*
sample output
Welcome to Triangle Maker 9000! Enter the size of the triangle: 3

*
**
***
**
*


*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote