Consider a staircase of size :
#
##
###
####
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.
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for(int i=0; i<n; i++) {
StringBuilder builder = new StringBuilder();
for(int j=0; j<(n-1-i); j++) builder.append(" ");
for(int j=(n-1-i); j<n; j++) builder.append("#");
System.out.println(builder.toString());
}
}
}'Programming > >> Algorithm' 카테고리의 다른 글
| [Lucky Algorithm] Time Conversion (0) | 2017.10.04 |
|---|---|
| [Lucky Algorithm] Birthday Cake Candles (0) | 2017.10.03 |
| [Lucky Algorithm] Plus Minus (0) | 2017.10.03 |
| [Lucky Algorithm] Diagonal Difference (0) | 2017.10.03 |
| [Lucky Algorithm] A Very Big Sum (0) | 2017.10.03 |
댓글