1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | package in.studyecart.sorting.array; import java.util.Arrays; import java.util.Scanner; public class NumSortArray { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.println(">> Array -Number -Sorting <<"); System.out.println("\nPlease Enter size of array:"); int asize=input.nextInt(); int arr[]=new int[asize]; //Scanning the numbers from user console area or you can directly take hard-code elements //like int arr[]= {323,454,656,768,678,980,345,620}; System.out.println("Please Enter "+asize +" of Elements into array: "); for(int i=0;i<arr.length;i++) { arr[i]=input.nextInt(); } //Using Arrays class static method sort() from java.util package; Arrays.sort(arr); //Ascending Order System.out.println("\nAfter Sorting arr[]:"); for(int i=0;i<arr.length;i++) { System.out.println(arr[i]); } } } |
Java Program to Sort(Ascending) an Given Array of Integers | Using Arrays.sort() | StudyEcart | Sorting003
August 17, 2022
0
Tags