본문 바로가기
알고리즘풀이/정올-자바

[정올/JAVA] 585 : 함수2 - 자가진단7

by 이얏호이야호 2020. 7. 25.

import java.util.Scanner;


public class Main {

public static void bubble(int[] arr) {

int temp;

for (int i = 0; i < arr.length - 1; i++) {

for (int j = 0; j < arr.length -1; j++) {

if (arr[j] < arr[j + 1]) {

temp = arr[j];

arr[j] = arr[j + 1];

arr[j + 1] = temp;

}

}


for (int num = 0; num < arr.length; num++) {

System.out.print(arr[num] + " ");

}

System.out.println();

}


}


public static void main(String args[]) {

Scanner in = new Scanner(System.in);

int[] arr = new int[10];

for (int i = 0; i < arr.length; i++) {

arr[i] = in.nextInt();

}

bubble(arr);

}

}

댓글