Advertisement
meteor4o

JA-Functions-CustomComparator

Oct 10th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class CustomComparator {
  5.     public static void main(String[] args) {
  6.         Scanner sc = new Scanner(System.in);
  7.  
  8.         Arrays.stream(sc.nextLine().split("\\s+"))
  9.         .map(Integer::parseInt)
  10.         .sorted((f, s) -> {
  11.             int result = 0;
  12.  
  13.             if (f % 2 == 0 && s % 2 != 0) {
  14.                 result = -1;
  15.             } else if (f % 2 != 0 && s % 2 == 0) {
  16.                 result = 1;
  17.             } else {
  18.                 result = f - s;
  19.             }
  20.             return result;
  21.         })
  22.         .forEach(e -> System.out.print(e + " "));
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement