Advertisement
Ligh7_of_H3av3n

03. Custom Min Function

May 27th, 2024
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. package Uprajnenie;
  2.  
  3. import java.util.Arrays;
  4. import java.util.Scanner;
  5. import java.util.function.Function;
  6.  
  7. public class CustomMinFunction {
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner(System.in);
  10.  
  11.  
  12.         String input = scanner.nextLine();
  13.  
  14.         Function<Integer[], Integer> smallestNumberFinder = numbers -> {
  15.             int smallest = numbers[0];
  16.             for (int i = 1; i < numbers.length; i++) {
  17.                 if (numbers[i] < smallest) {
  18.                     smallest = numbers[i];
  19.                 }
  20.             }
  21.             return smallest;
  22.         };
  23.  
  24.         Integer[] numbers = Arrays.stream(input.split("\\s+"))
  25.                 .map(Integer::parseInt)
  26.                 .toArray(Integer[]::new);
  27.  
  28.         System.out.println(smallestNumberFinder.apply(numbers));
  29.     }
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement