본문 바로가기
코딩테스트 준비/백준

[백준] 2562번 - 최댓값 [Java]

by mwzz6 2024. 12. 29.

https://www.acmicpc.net/problem/2562

 

[백준] 2562번 - 최댓값 [Java]
[백준] 2562번 - 최댓값 [Java]


1.  아이디어

 

반복문과 조건문을 조합하면 간단하게 해결할 수 있다.


2. 문제풀이

 

아이디어 그대로 구현했다.


3. 코드

 

import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int max = 0;
        int order = 0;

        for (int i = 1; i <= 9; i++) {
            int num = Integer.parseInt(br.readLine());

            if (num > max) {
                max = num;
                order = i;
            }
        }

        System.out.println(max);
        System.out.println(order);
    }
}

4. 후기