[HackerRank] Staircase

311 查看

Problem

Your teacher has given you the task of drawing a staircase structure. Being an expert programmer, you decided to make a program to draw it for you instead. Given the required height, can you print a staircase as shown in the example?

Input
You are given an integer N depicting the height of the staircase.

Output
Print a staircase of height N that consists of # symbols and spaces. For example for , here's a staircase of that height:

     #
    ##
   ###
  ####
 #####
######

Note

The last line has 0 spaces before it.

Solution

import java.io.*;
import java.util.*;
public class Solution {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        char [] curRow = new char [n];
        Arrays.fill(curRow, ' ');
        int i = 0;
        for (i = 1; i <= n; i++){
            curRow[n-i] = '#';
            System.out.println(curRow);
        } 
    }
}