[HackerRank] Staircase

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

关键字:java, staircase, currow, height


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部