본문 바로가기

백준 문제풀기/JAVA

[백준 10871 JAVA 자바] X보다 작은 수

수열 중에서

X보다 작은 수들을 출력합시다

 

크게 어렵지 않은 문제입니다

n과 x를 잘 저장해서

n만큼 반복 입력 할 때

x보다 큰지 작은지 판단을 할 때 마다

출력을 해봅시다

 

코드입니다

 

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

어렵지 않스무니