hwangnk1004 / Algorithm

0 stars 0 forks source link

StepByStep #두수 #257

Open hwangnk1004 opened 4 years ago

hwangnk1004 commented 4 years ago

import java.util.Scanner;

public class Main { public static void main(String args[]) {

    Scanner scanner = new Scanner(System.in);

    int[] arr = new int[20];
    int empty = 0;

    for (int i = 0; i < arr.length; i++) {
        arr[i] = scanner.nextInt();

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

            if (arr[i] >= arr[j]) {
                empty = arr[i];
                arr[i] = arr[j];
                arr[j] = empty;
            }
        }
    }

    System.out.println(arr[arr.length - 1] + arr[arr.length - 2]);
    System.out.println(arr[arr.length - 1] + " " + arr[arr.length - 2]);
}

}