Tag Archives: java pattern program

java program to print pattern

Java Porgram to print pattern

Write a java program to prints a staircase of size  n like below show .

Java Porgram to print pattern

Java Porgram to print pattern

Input Data

An integer n , that represent the size of the staircase (pattern).

Output Data

Print a staircase (pattern) of size using # symbols and spaces using Java.

Explanation

The staircase (pattern) is right-aligned, composed of # symbols and spaces, and has a height and width of n=6

import java.util.*;

public class Pattern {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
       for (int k=1;k<=n;k++){
        for (int k1=1;k1<=n-k;k1++){
            System.out.printf(" ");
        }
        for (int i=1;i<=k;i++){
            System.out.print("#");
        }
        System.out.println("");
    }
    }
}