Skip to content

Half Pyramid

Right-aligned half-pyramid of stars.

package DSA.Patterns;
import java.util.Scanner;
public class halfpyramid {
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
System.out.println("Enter a number");
int n = sc.nextInt();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j);
}
System.out.println();
}
} catch (Exception e) {
System.out.println(e);
}
}
}