📝 문제
❗ 주의
X보다 작은 수를 입력받은 순서대로 공백으로 구분해 출력한다. 를 확인.
System.out.println()이 아닌, System.out.print()를 사용한다.
🔓 답안
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(); // 배열의 크기
int x = sc.nextInt(); // x보다 작은 수를 출력하는 것이 목표
int[] a = new int[n];
// 배열 입력받기
for(int i = 0; i < n; i++){
a[i] = sc.nextInt();
}
// 배열 돌면서 x보다 작은 수 찾기
for(int i = 0; i < n; i++){
if(a[i] < x){
System.out.print(a[i] + " ");
}
}
sc.close();
}
}
'PS > Baekjoon' 카테고리의 다른 글
[Baekjoon] 10926 - ??! (0) | 2022.11.05 |
---|---|
[Baekjoon] 2742 - 기찍 N (0) | 2022.11.04 |
[Baekjoon] 10807 - 개수 세기 (0) | 2022.11.04 |
[Baekjoon] 10950 - A+B - 3 (0) | 2022.11.03 |
[Baekjoon] 2739 - 구구단 (0) | 2022.11.03 |
댓글