Using Nested Loop Inverted Star Pattern
import java.util.Scanner;
public class InvertedStarPattern {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int line = 1; line <= n; line++) {
// one line
for (int star = 1; star <= n - line + 1; star++) {
System.out.print("*");
}
System.out.println("");
}
}
}
Output:
7
*******
******
*****
****
***
**
*
No comments:
Post a Comment