상세 컨텐츠

본문 제목

[백준/BAEKJOON] 10871번 X보다 작은 수 JAVA

코딩/BAEKJOON

by JEONJIHO 2021. 9. 7. 22:48

본문


1.

첫 줄에 입력받을 N과 X보다 작은 수를 입력한다.

 

2.

N만큼 숫자를 랜덤하게 입력한다.

 

3. 

FOR문을 돌면서 X보다 작은수만을 출력한다.

 

 


 

import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
 
		int N = in.nextInt();
		int X = in.nextInt();
		int arr[] = new int[N];
        
		for (int i = 0; i < N; i++) {
			arr[i] = in.nextInt();
		}
 
		in.close();
        
		for (int i = 0; i < N; i++) {
			if (arr[i] < X) {
				System.out.print(arr[i] + " ");
			}
		}
	}
}

 

관련글 더보기

댓글 영역