import java.util.Scanner;

class BubbleSorting{

  public static void main(String[] args) throws Exception {

    int[] arr = {3, 6, 8, 4, 12, 1, 9, 7};

    int i = 0;
    int temp;

    int end = arr.length -1;
    while (end > 0) {
       i = 0;
        while (i < end) {
          if (arr[i] > arr[i+1]) {
            temp = arr[i];
            arr[i] = arr[i+1];
            arr[i+1] = temp;
          }
          i += 1;
        }
      end--;
    }
 
    for (int each : arr)
    System.out.printf("%d \n", each);


   }
}

Posted by 안낭우훗

블로그 이미지
좋은싸이트 공유, 재해석 , 공부 정리, 틀린거 알려 주세요~
안낭우훗

태그목록

공지사항

Yesterday
Today
Total

달력

 « |  » 2025.6
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30

최근에 올라온 글

최근에 달린 댓글

글 보관함