Advertisement
Hiteshw11

Array Elements in Ascending Order

Jan 20th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. import java.util.*;
  2. class Ascending2 {
  3.     public static void main(String[] args) {
  4.         Scanner src=new Scanner(System.in);
  5.         int n;
  6.         System.out.println("Enter the size of the Array");
  7.         n=src.nextInt();
  8.         int arr[]=new int[n];
  9.         for(int i=0;i<n;i++)
  10.         {
  11.             System.out.println("Enter the element");
  12.             arr[i]=src.nextInt();
  13.         }
  14.         Arrays.sort(arr);
  15.         System.out.println("The elements in ascending order are");
  16.         for(int j=0;j<n;j++)
  17.         {
  18.             System.out.println(arr[j]);
  19.         }
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement