Challenge: Sort and Show

Lab Java Beginner 10 points

Read n and then n whole numbers. Print them sorted from smallest to largest using Arrays.toString.

Input

First n, then n whole numbers.

Output

The sorted array, e.g. [1, 2, 5, 9].

Example

Input

4
5 2 9 1

Output

[1, 2, 5, 9]
Sample input available Sample output available
Editor
Java

Hints

import java.util.Arrays;

Arrays.sort(a) sorts the array in place.

Solution explanation

Arrays.sort sorts the array itself, then Arrays.toString prints it with brackets and commas.

Show solution
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[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        System.out.println(Arrays.toString(a));
    }
}
Output
Answer
HOME LABS COMMUNITY DASHBOARD