# 1등은 누구? for(int i = 0; i<arr.length; i++) { if( arr[i] > arr[topScore]){ topScore = i; } 여기서 if 안의 조건식 이 arr[] 형식으로 되어있어서 topScore = i 도 인덱스 값으로 들어가는건가요? #### CODE <a class='btn btn-default' href='/codes/44612'>Link</a> ``` public class TopScoreStudent { public static void main(String[] args) { // 배열 생성 String[] names = {"Elena" , "Suzie" , "John" , "Emily" , "Neda" , "Kate" , "Alex" , "Daniel"}; int[] scores = {65, 74 , 23 , 75 , 68 , 96 , 88 , 98}; // 1등 인덱스 검색 int i = topIndex(scores); // 결과 출력 System.out.printf("1등: %s(%d점)\n", names[i], scores[i]); } // 정수형 배열을 입력받아 가장 큰 값의 인덱스를 반환 public static int topIndex(int[] arr) { /* 해당 함수를 완성하세요. */ int topScore = 0 ; for (int i = 0 ; i<arr.length; i++){ if (arr[i]>arr[topScore]){ topScore = i; } } return topScore; } } ``` #### INPUT ``` ``` #### OUPUT ``` 1등: Daniel(98점) ```
혹시 for문으로 증가하는게 arr[i] 의 인덱스 값이고 인덱스에 레퍼런스 되는 값에 비교되어 더큰수가 topScore 에 담겨서 다음에 증가되는 arr[i]의 레퍼런스 값과 비교되는거 맞을까요?
## 자세한 내용은 변수 `i`는 배열의 인덱스를 순회하기 위한 것이고, 변수 `topScore`는 배열을 순회하며 현재 까지 찾은 가장 큰 값의 위치를 저장키 위해 만든 것입니다. 보다 자세한 내용은 해당 강의를 참고해보세요 https://youtu.be/Sa0uLYTE6vc