본문 바로가기
💻 문제풀고 정리하기 +/백준

[백준 Java] 10871: X보다 작은 수

by 종이빨대 2023. 9. 5.
TOP

목차

    1. 문제

    2. 맞춘코드

    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.io.IOException;
    import java.util.StringTokenizer;
    
    public class bj10871{
    	public static void main(String[] args) throws IOException {
    		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    		StringTokenizer st = new StringTokenizer(br.readLine(), " ");
    
    		// 변수 선언 및 입력받기-1(첫째줄)
    		int n = Integer.parseInt(st.nextToken());	// 받을 정수 갯수
    		int x = Integer.parseInt(st.nextToken());	// 기준 정수
    		
    		// 배열 선언
    		st = new StringTokenizer(br.readLine(), " ");
    		int[] arr = new int[n];
    		for(int i=0; i<arr.length; i++){
    			arr[i] = Integer.parseInt(st.nextToken());
    		}
    		
    		// x보다 작은수 출력
    		for(int i=0; i<arr.length; i++){
    			if(arr[i]<x)
    				System.out.printf("%d ",arr[i]);
    		}
    		
    	}
    }

    '💻 문제풀고 정리하기 + > 백준' 카테고리의 다른 글

    [백준 Java] 2562: 최댓값  (1) 2023.09.05
    [백준 Java] 10818: 최소, 최대  (0) 2023.09.05
    [백준 Java] 10807: 개수 세기  (1) 2023.09.05
    [백준 Java] 10951: A+B - 4  (0) 2023.09.02
    [백준 Java] 10952: A+B - 5  (0) 2023.09.02