본문 바로가기
알고리즘/Java

버블 정렬(Java)

by 싸공 2020. 7. 10.
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
 
public class bubble {
    public static void main(String[] args) {
        int i = 0;
        int j = 0;
        int k = 0;
        int a = 0;
        int arr[] = {1346792580};
        
        while(i<9) {
            i++;
            j = -1;
            while(j< 9 - i){
                j++;
                if (arr[j] > arr[j + 1]){
                    k = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1= k;
                }
            }
        }
        while(a <= 9) {
            System.out.print(arr[a] + " ");
            a++;
        }
        
    }
}
cs

 

출력 화면