Untitled
unknown
plain_text
2 years ago
951 B
8
Indexable
import java.util.Arrays;
public class SortArray {
public static void main(String[] args) {
// Check if command line arguments are provided
if (args.length == 0) {
System.out.println("Please provide integer values as command line arguments.");
return;
}
// Initialize integer array with command line arguments
int[] array = new int[args.length];
for (int i = 0; i < args.length; i++) {
try {
array[i] = Integer.parseInt(args[i]);
} catch (NumberFormatException e) {
System.out.println("Invalid input. Please provide only integer values.");
return;
}
}
// Sort the array
Arrays.sort(array);
// Display the sorted array
System.out.print("Sorted Array: ");
for (int value : array) {
System.out.print(value + " ");
}
}
}Editor is loading...
Leave a Comment