Question

Write a Java program that reads in a positive integer from the user and outputs the...

Write a Java program that reads in a positive integer from the user and outputs the following triangle shape composed of asterisk characters.

For example, if user enters 5 as the input, then your program should display the following shape:

*****
****
***
**
*
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

import java.lang.*;
import java.util.Scanner;
public class Triangle {
public static void main(String[] args) {
int input;
   Scanner s = new Scanner(System.in);
   input = s.nextInt();
for(int i = input; i >= 1; i--) {
for(int j = 1; j <= i; j++) {
System.out.print("*");
}
System.out.println();
}
}
}

Output:

Explanation:

Add a comment
Know the answer?
Add Answer to:
Write a Java program that reads in a positive integer from the user and outputs the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT