입력받은 숫자 세개 내림차순 정렬




package Pack_desc;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		double[] num = new double[3];
		System.out.print("숫자 세 개를 입력하세요 : ");
		for (int i = 0; i < num.length; i++) {
			num[i] = scanner.nextDouble();
		}
		scanner.close();
		
		for (int i = 0; i < num.length; i++) {
			for (int j= i+1; j < num.length; j++) {
				if (num[i] < num[j]) {
					double tmp = num[i];
					num[i] = num[j];
					num[j] = tmp;
				}
				
			}
			
		}
		for (int i = 0; i < num.length; i++) {
			System.out.print(num[i] + "  ");
			
		}
	}

}

결과

quiz

Leave a comment