- 성적표를 보고 최고 득점자를 뽑으려 한다 주어진 메소드를 이용하여 최고 득점자를 뽑으시오
- 최고 득점자를 뽑을 때는 topIndex()를 정의하고 사용하시오
- 출력 예시
public class MaxRank {
public static int topIndex(int[] scores) {
int topIndex=0;
for(int i=1; i<scores.length; i++) {
if(scores[i-1]<scores[i]) {
topIndex = i;
}else {
topIndex = i-1;
}
}
return topIndex;
}
public static void main(String[] args) {
// 주어진 메소드를 이용하여 최고 득점자를 뽑기
//최고 득점자를 뽑을 때는 topIndex()를 정의
String[] names = {"Elena", "Suzie", "John", "Emily", "Neda", "Kate", "Alex", "Daniel", "Hamilton"};
int[] scores = {65, 74, 23, 75, 68, 96, 88, 98, 54};
int MaxRank = topIndex(scores);
System.out.printf("1등: %s(%d점)\n", names[MaxRank], scores[MaxRank]);
}
}