You are given an integer n which is the number of rows of an inverted pyramid made up of asterisks (*). Write a Java program to create an inverted pyramid of asterisks. For a given n, print n lines where the i-th line has (n - i + 1) asterisks, for i from 1 to n. Each line of the pyramid should end with a newline character ('\n').
For loop
Generate an inverted pyramid from asterisks
Report a typo
Sample Input 1:
5Sample Output 1:
*****
****
***
**
*Sample Input 2:
3Sample Output 2:
***
**
*Write a program in Java 25
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Get the number of rows for the pyramid
int n = scanner.nextInt();
// For each row..
// write a loop that starts at 'n' and ends at 1 (hint: you can use a decrement)
// For each column..
// write another loop inside the first one that starts at the current row number and ends at 1
// print an asterisk ('*') without going to the next line (use 'System.out.print' instead of 'println')
// After each row, print a newline character ('\n')
}
}
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.