Observe that its base and height are both equal to , and the image is drawn using
# symbols and spaces. The last line is not preceded by any spaces.
Write a program that prints a staircase of size .
Input Format
A single integer, , denoting the size of the staircase.
Output Format
Print a staircase of size using
# symbols and spaces.
Note: The last line must have spaces in it.
package com.rohan.test;
import java.util.Scanner;
public class StaircaseTest {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for(int i = 0; i< n; i++) {
for(int k = 0; k < n; k++) {
if(k < n-i-1)
System.out.print(" ");
else
System.out.print("#");
}
System.out.println();
}
}
}
Sample Input
6
Sample Output
#
##
###
####
#####
######
Comments
Post a Comment