Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.Arrays;
- class Sorting{
- private static String getInput(String prompt){
- BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
- System.out.print(prompt);
- System.out.flush();
- try{
- return stdin.readLine();
- }catch(Exception e){
- return "Error: " + e.getMessage();
- }
- }
- static public void main (String[] args){
- String input = getInput("Enter the size of the array: ");
- int n = Integer.parseInt(input);
- int [] a = new int [n];
- System.out.println("Now enter "+n+" numbers");
- for(int i = 0; i < n; i++){
- input = getInput("Enter element: ");
- a[i] = Integer.parseInt(input);
- }
- Arrays.sort(a);
- for (int number : a)
- System.out.println(+number);
- }
- }
- // Output:-
- // C:\Java>java Sorting
- // Enter the size of the array: 10
- // Now enter 10 numbers
- // Enter element: 43
- // Enter element: 12
- // Enter element: 54
- // Enter element: 1
- // Enter element: 85
- // Enter element: -23
- // Enter element: 9
- // Enter element: 0
- // Enter element: 199
- // Enter element: 4000
- // -23
- // 0
- // 1
- // 9
- // 12
- // 43
- // 54
- // 85
- // 199
- // 4000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement