망나니 AWOS의 일상
article thumbnail

문제의 핵심은 오름차순으로 정렬하는 것이다.

이 문장을 보자마자 Arrays.sort()라는 메소드를 이용하면 쉽게 풀 수 있을 것 같아 바로 적용하였다.

기본적으로 오름차순 정렬이기 때문에 간단하게 한줄 써주면 된다.

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] arr = new int[N];
        for(int i=0; i<N; i++){
            arr[i] = sc.nextInt();
        }

        Arrays.sort(arr);

        for(int i : arr)
            System.out.println(i);
    }
}

 

 

profile

망나니 AWOS의 일상

@AWOS

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!