충분히 쌓여가는
백준[Java] 2438번 별 찍기 -1 본문
https://www.acmicpc.net/problem/2438
문제 풀이 1
import java.util.Scanner;
public class _2438_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 = 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 _2438_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 = 1; j <= i; j++) {
System.out.print('*');
}
System.out.println();
}
}
}
문제 풀이 3
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class _2438_3 {
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 = 1; j <= i; j++) {
sb.append('*');
}
sb.append('\n');
}
System.out.println(sb);
}
}
문제 풀이 4
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.IOException;
public class _2438_4 {
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 = 1; j <= i; j++) {
bw.write('*');
}
bw.newLine();
}
bw.flush();
bw.close();
}
}
'IT > Java[백준]' 카테고리의 다른 글
백준[Java] 10952번 A+B-5 [charAt 사용] (0) | 2023.02.22 |
---|---|
백준[Java] 2439번 별 찍기 -2 (0) | 2023.02.21 |
백준[Java] 11022번 A+B-8 (0) | 2023.02.20 |
백준[Java] 11021번 A+B-7 (0) | 2023.02.20 |
백준[Java] 8393번 합 (*문제는 쉽지만 시간초과에 대한 문제! 중요!) (2) | 2023.02.17 |