Write down a java program which will print a staircase pattern of * with 10 levels.
import java.util.Scanner;
public class Main {
public static void myStairs(int h, int y){
for (int i = 0; i < h; i++) {
for (int j = 0; j < i * (y - 1); j++) {
System.out.print(" ");
}
for (int k = 0; k < y; k++) {
System.out.print("*");
}
System.out.println();
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the height of the stairs");
int heigh = scanner.nextInt();
System.out.println("Enter the length of the steps");
int length = scanner.nextInt();
myStairs(heigh, length);
}
}
Comments
Leave a comment