打印一個樓梯(Staircase)


打印一個高度爲N由#符號填充的樓梯

比如N=6時

打印

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

我的解答:

import java.io.*;
import java.util.*;

public class Staircase {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        
        for(int row = 0; row < N; row ++){
            for(int space = 0; space < N - row - 1; space++){
                System.out.print(" ");
            }
            for(int sharp = 0; sharp < row + 1; sharp++){
                System.out.print("#");
            }
            System.out.println();
        }
    }
}


發佈了40 篇原創文章 · 獲贊 6 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章