충분히 쌓여가는
백준[Java] 2439번 별 찍기 -2 본문
https://www.acmicpc.net/problem/2439
문제 풀이 1
import java.util.Scanner;
public class _2439_1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
sc.close();
for (int i = 1; i <= N; i++) {
for (int j = 0; j < N-i; j++) {
System.out.print(' ');
}
for (int j = 1; j <= i; j++) {
System.out.print('*');
}
System.out.println();
}
}
}
문제 풀이 2
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class _2439_2 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
br.close();
for (int i = 1; i <= N; i++) {
for (int j = 0; j < N-i; j++) {
System.out.print(' ');
}
for (int j = 1; j <= i; j++) {
System.out.print('*');
}
System.out.println();
}
}
}
문제 풀이 3
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class _2439_3 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int N = Integer.parseInt(br.readLine());
br.close();
for (int i = 1; i <= N; i++) {
for (int j = 0; j < N-i; j++) {
bw.write(' ');
}
for (int j = 1; j <= i; j++) {
bw.write('*');
}
bw.newLine();
}
bw.flush();
bw.close();
}
}
문제 풀이 4
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class _2439_4 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
br.close();
StringBuilder sb = new StringBuilder();
for (int i = 1; i <= N; i++) {
for (int j = 0; j < N-i; j++) {
sb.append(' ');
}
for (int j = 1; j <= i; j++) {
sb.append("*");
}
sb.append('\n');
}
System.out.println(sb);
}
}
'IT > Java[백준]' 카테고리의 다른 글
백준[Java] 10951번 A+B-4 (hasNextInt 사용 [중요!]) (1) | 2023.02.23 |
---|---|
백준[Java] 10952번 A+B-5 [charAt 사용] (0) | 2023.02.22 |
백준[Java] 2438번 별 찍기 -1 (0) | 2023.02.21 |
백준[Java] 11022번 A+B-8 (0) | 2023.02.20 |
백준[Java] 11021번 A+B-7 (0) | 2023.02.20 |