최댓값 (2562)

유지원·2021년 8월 12일
0

백준OJ

목록 보기
32/32
post-thumbnail

Java 11

  • 배열 O
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {

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

        int[] arr = new int[9];

        for (int i=0; i<9; i++) {
            arr[i] = Integer.parseInt(br.readLine());
        }

        int max = 0;
        int index = 0;
        int count = 0;

        for (int value : arr) {
            count ++;
            if (value > max) {
                max = value;
                index = count;
            }
        }

        System.out.println(max);
        System.out.println(index);
    }
}
  • 배열 X
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {

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

        int max = 0;
        int index = 0;

        for (int i=0; i<9; i++) {
            int val = Integer.parseInt(br.readLine());
            if (val > max) {
                max = val;
                index = i+1;
            }
        }

        System.out.println(max);
        System.out.println(index);
    }
}
profile
👋 https://github.com/ujw0712

0개의 댓글