백준 FYI

KIMYEONGJUN·2025년 1월 26일
0
post-thumbnail

문제

내가 생각했을때 문제에서 원하는부분

The input consists of a single line containing a 7-digit positive integer N, (1000000 <= N <= 9999999).

The single output line consists of the word YES if the number should be routed to the directory information operator or NO if the number should not be routed to the directory information operator.

내가 이 문제를 보고 생각해본 부분

BufferedReader 객체 br을 생성하여 입력(System.in)으로부터 데이터를 읽어온다.
br.readLine() 메서드를 사용하여 사용자로부터 한 줄의 입력을 읽고, 그것을 number라는 문자열 변수에 저장한다.
전화번호 접두사 확인:
startsWith("555") 메서드를 사용하여 입력된 전화번호가 "555"로 시작하는지 확인한다.
조건이 참이면 "YES"를 출력하고, 그렇지 않으면 "NO"를 출력한다.

코드로 구현

package baekjoon.baekjoon_26;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

// 백준 17863번 문제
public class Main913 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String number = br.readLine(); // 7자리 전화번호 입력

        if(number.startsWith("555")) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

        br.close();
    }
}

마무리

코드와 설명이 부족할수 있습니다. 코드를 보시고 문제가 있거나 코드 개선이 필요한 부분이 있다면 댓글로 말해주시면 감사한 마음으로 참고해 코드를 수정 하겠습니다.

profile
Junior backend developer

0개의 댓글

관련 채용 정보