티스토리 뷰

1. 문제

2. 정답

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();
if(0<n&&n<10000){
int[]arr = new int[n];
    }
for(int i =0; i<n; i++){
 int t = sc.nextInt();
  if(x>t)
    System.out.println(t);
}
  System.out.println(" ");
  }
}

3. 분석

스캐너를 이용하여 n과x를 입력할 수 있게 만들고, 배열을 선언한다.
이때 x보다 작은 수만 출력해야하므로 if를 사용하여 조건식을 만들어 조건에 맞는 수만 출력하도록 한다.

 

'CodingTest > JAVA' 카테고리의 다른 글

백준(BAEKJOON) | 2526번 | 최댓값  (0) 2022.12.15
백준(BAEKJOON) | 3052번 | 나머지  (0) 2022.12.13
백준(BAEKJOON) | 10807번 | 개수 세기  (0) 2022.12.12
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함