EmiliaKitkarska

Zadacha5

Apr 19th, 2021
703
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 5. Сортиране на числа
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Collections;
  5. import java.util.List;
  6. import java.util.Scanner;
  7.  
  8. public class Zadachki {
  9.  
  10.     public static void print(List<Integer> numbers) {
  11.         System.out.print(numbers.get(0));
  12.         for (int i = 1; i < numbers.size() - 1; i++) {
  13.             System.out.print(" <= " + numbers.get(i));
  14.         }
  15.         System.out.print(" <= " + numbers.get(numbers.size() - 1));
  16.     }
  17.  
  18.     public static void main(String[] args) {
  19.         Scanner scan = new Scanner(System.in);
  20.         String[] input = scan.nextLine().split(" ");
  21.         List<Integer> numbers = new ArrayList<>();
  22.  
  23.         for (String val : input) {
  24.             numbers.add(Integer.parseInt(val));
  25.         }
  26.  
  27.         Collections.sort(numbers);
  28.         print(numbers);
  29.  
  30.  
  31.     }
  32. }
  33.  
RAW Paste Data