본문 바로가기

Study/algorithm

백준 자바 알고리즘 [최댓값]

 

Scanner sc = new Scanner(System.in);

    int []a = new int[9];
    int cut = 0;
    int max = 0;
        for (int i = 0; i < 9; i++) {
            a[i] = sc.nextInt();
            if (max<a[i]) {
                max = a[i];
                cut++;  // cut = i+1 로 해도된다 인덱스+1 
            }
        }
        System.out.println(max);
        System.out.println(cut);

 

최소,최대 문제와 다르지 않은 문제이다.

최댓값만 구해주고 거기에 카운트만 넣어주면 된다.