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("");
    }
    }
}


The following two tabs change content below.
Umar Farooque Khan is Software developer/ web developer and professional blogger serving Worldwide on freelancer and ODesk platform to show the capability of his skills He is the founder of pTutorial.com. The main purpose of this site is sharing and exchanging of I.T. Knowledge.

Latest posts by Umar Farooque Khan (see all)