[java] 백준 단계별로 풀어보기 3단계 (3)알고리즘/백준2021. 6. 24. 00:14
Table of Contents
9단계 2438번 별 찍기 - 1
import java.util.Scanner;
class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
for(int i=1; i<=a; i++){
for(int j=1; j<=i; j++){
System.out.print("*");
}
System.out.println();
}
}
}
10단계 2439번 별 찍기 - 2
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
// 공백이 4개 + 별 1개
for(int i=1; i<=a; i++) {
for(int k=1; k<=a-i; k++){
System.out.print(" ");
}
for(int j=1; j<=i; j++){
System.out.print("*");
}
System.out.println();
}
}
}
11단계 10871번 X 보다 작은 수
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int X = sc.nextInt();
int arr[] = new int[N];
for(int i=0; i<N; i++) {
arr[i] = sc.nextInt();
if(arr[i] < X)
System.out.print(arr[i]+" ");
}
}
}
11번 같은 경우 BufferedReader, BufferedWriter로 로직을 짜다가 N과 X를 입력받는 부분에서 space bar를 경계로 인식하기 위해서는 내가 알고 있는 지식 선에서는 Scanner 밖에 답이 없어서 Scanner로 로직을 변경하였다.
'알고리즘 > 백준' 카테고리의 다른 글
[java] 백준 단계별로 풀어보기 5단계 (1) (0) | 2021.06.28 |
---|---|
[java] 백준 단계별로 풀어보기 4단계 (0) | 2021.06.25 |
[java] 백준 단계별로 풀어보기 3단계 (2) (0) | 2021.06.23 |
[java] 백준 단계별로 풀어보기 3단계 (1) (0) | 2021.06.19 |
[java] 백준 단계별로 풀어보기 2단계 (0) | 2021.06.17 |
@펄찌 :: Pearl's Story
펄의 일상이 궁금한 사람 요기~
즐거운 하루 되셨으면 좋겠습니다😊