Untitled

 avatar
unknown
plain_text
a year ago
943 B
7
Indexable
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        // Check if there are command line arguments
        if (args.length == 0) {
            System.out.println("No input provided.");
            return;
        }
        
        // Create an array to store the input values
        int[] array = new int[args.length];
        
        // Parse and store the input values
        for (int i = 0; i < args.length; i++) {
            try {
                array[i] = Integer.parseInt(args[i]);
            } catch (NumberFormatException e) {
                System.out.println("Invalid input: " + args[i]);
                return;
            }
        }
        
        // Sort the array
        Arrays.sort(array);
        
        // Display the sorted array
        System.out.println("Sorted array:");
        for (int num : array) {
            System.out.print(num + " ");
        }
    }
}
Editor is loading...
Leave a Comment