Baekjoon Algorithm | Problem 2439: Print Stars - 2
Source
https://www.acmicpc.net/problem/2438
Problem
Solve Baekjoon Online Judge problem 2439, Print Stars - 2.
Input
Follow the input format and constraints given in the original problem statement.
Output
Print the answer required by the problem.
Sample Input 1
5
Sample Output 1
\* \** \*** \**** \*****
Algorithm Classification
- Implementation
Solution
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);
}
}
}
}