Advertisement
CR7CR7

sortArr

Oct 17th, 2022
1,032
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class SortNumbers {
  5.  
  6.     public static void main(String[] args) {
  7.  
  8.         Scanner scanner = new Scanner(System.in);
  9.         String[] input = scanner.nextLine().split(", ");
  10.         int[] numbers = new int[input.length];
  11.         for (int i = 0; i < input.length; i++) {
  12.             numbers[i] = Integer.parseInt(input[i]);
  13.         }
  14.  
  15.         Arrays.sort(numbers);
  16.  
  17.         int length = numbers.length;
  18.         int[] revArr = new int[length];
  19.  
  20.         for (int j = 0; j < length; j++) {
  21.             revArr[length - j - 1] = numbers[j];
  22.         }
  23.  
  24.         String[] numbersAsStrings = new String[revArr.length];
  25.         for (int i = 0; i < revArr.length; i++) {
  26.             numbersAsStrings[i] = Integer.toString(revArr[i]);
  27.         }
  28.         String output = String.join(", ", numbersAsStrings);
  29.  
  30.         System.out.println(output);
  31.  
  32.     }
  33. }
Advertisement
Comments
  • Francisc0
    2 years
    # text 0.11 KB | 0 0
    1. mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMARIO
Add Comment
Please, Sign In to add comment
Advertisement