Answer to Question #155394 in Java | JSP | JSF for joy

Question #155394

Write down a java program which will print a staircase pattern of * with 10 levels.


1
Expert's answer
2021-01-14T11:37:22-0500
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);


    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog