Baekjoonアルゴリズム | 2439番問題: 星を出力 - 2
出典
https://www.acmicpc.net/problem/2438
問題
Baekjoon Online Judgeの2439番問題、星を出力 - 2を解きます。
入力
正確な入力形式と制約は元の問題文に従います。
出力
問題で求められる答えを出力します。
サンプル入力 1
5
サンプル出力 1
\* \** \*** \**** \*****
アルゴリズム分類
- 実装
解説
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
int input = Integer.parseInt(br.readLine());
String space = "";
for (int i = 0; i < input - 1; i++) {
space = space + " ";
}
String star = "";
for (int i = 0; i < input; i++) {
star = star + "*";
System.out.println(space.substring(0, space.length() - i) + star);
}
}
}
}