Java program to sort array using Sort method
Program
import java.util.Arrays;
import java.util.Scanner;
public class SortArrayUsingSortMethod {
public static void main(String[] args) {
int i= 0;
System.out.println("Enter the required size of the array: ");
Scanner reader = new Scanner(System.in);
int size = reader.nextInt();
int inputArray[] = new int[size];
System.out.println("Enter the elements of the array: ");
for (i = 0; i < size; i++) {
inputArray[i] = reader.nextInt();
}
Arrays.sort(inputArray);
System.out.println("Array elements sorted in ascending order: ");
for (i = 0; i < inputArray.length; i++) {
System.out.println(inputArray[i]);
}
}
}
Output
javac .\SortArrayUsingSortMethod.java
java SortArrayUsingSortMethod
Enter the required size of the array:
6
Enter the elements of the array:
89
23
11
56
45
8
Array elements sorted in ascending order:
8
11
23
45
56
89