1차 배열 내림차순 정렬

2024. 6. 1. 08:03정보처리,전산/JAVA

반응형
public class Main{

  public static void main(String[] args){
   int[] score ={60,30,50,30,52,31,24,63,75,36,24};
    int temp = 0;
    for (int i = 0;i<score.length;i++){
      for(int j =i+1;j<score.length;j++){
        if(score[i]<score[j]){
          temp=score[i];
          score[i]=score[j];
          score[j]=temp;
        }
      }
      System.out.println(score[i]); 
      
      
      }
    
  }
}

 

앞 뒤 값을 비교하여 큰 값이 앞으로 쌓이도록 정렬

반응형

'정보처리,전산 > JAVA' 카테고리의 다른 글

생성자의 오버로딩 (Overloading)  (0) 2024.07.17
화씨 값을 섭씨 값으로 변환  (0) 2024.07.16
2차원 배열  (0) 2024.06.01
ArrayIndexOutOfBoundsException  (0) 2024.05.08
객체 생성  (0) 2024.04.21