desislava_topuzakova

03. Custom Min Function

Sep 30th, 2021
820
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Collections;
  3. import java.util.List;
  4. import java.util.Scanner;
  5. import java.util.function.*;
  6. import java.util.stream.Collectors;
  7.  
  8. public class FormulaOne_02 {
  9.     public static void main(String[] args) {
  10.         //Function<приема, връща> -> apply
  11.         //Consumer<приема> -> void -> accept
  12.         //Supplier<връща> -> get
  13.         //Predicate<приема> -> false / true -> test
  14.         //BiFunction<приема1, приема2, връща> -> apply
  15.         Scanner scanner = new Scanner(System.in);
  16.         String input = scanner.nextLine(); //"1 4 3 2 1 7 13".split(" ") -> ["1", "4", ....]
  17.         List<Integer> numbers = Arrays.stream(input.split("\\s+")).map(Integer::parseInt).collect(Collectors.toList());
  18.  
  19.         //начин 1
  20.         //лист -> върнем мин число
  21.         /*Function<List<Integer>, Integer> getMinNumber = list -> Collections.min(list);
  22.         System.out.println(getMinNumber.apply(numbers));*/
  23.  
  24.         //начин 2
  25.         //лист -> отпечатаме мин число
  26.         Consumer<List<Integer>> printMinNumber = list -> System.out.println(Collections.min(list));
  27.         printMinNumber.accept(numbers);
  28.  
  29.         //начин 3
  30.         //System.out.println(Collections.min(numbers));
  31.  
  32.  
  33.  
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment