본문 바로가기

콩's EDUCATION/콩's JAVA_RUN

최고점 이름, 점수 정렬 배열

최고점 이름, 점수 정렬


 

 

public class MaxTest {
 public static void main(String[] args) {
  String name[] = new String[] { "임꺽정", "강감찬", "이순신", "율곡", "신사임당" };
  int score[] = new int[]{90, 99, 100, 85, 20};

  for (int i = 1; i < score.length; i++) {
   if (score[0] < score[i]) {
    int temp = score[0];
    score[0] = score[i];
    score[i] = temp;
    
    String temp2 = name[0];
    name[0] = name[i];
    name[i] = temp2;
   }
  }
  for(int k=0;k<score.length;k++){
   System.out.println(score[k]);
  }
   System.out.println("최고점 점수 "+name[0]);
   System.out.println("최고점 이름 "+score[0]);
 }
}

 

 

MaxTest.java