fork download
  1. /* package whatever; // don't place package name! */
  2. import java.io.BufferedReader;
  3. import java.io.InputStreamReader;
  4. import java.util.function.Function;
  5. import java.util.stream.IntStream;
  6.  
  7. public class Main {
  8. public static void main(String[] args) throws Exception {
  9. int sum = 42;
  10. int read = 0;
  11. Function<Integer, Integer> cont = IntStream.range(0, 3).mapToObj(i -> (Function<Integer, Integer>) x -> {
  12. try {
  13. return x + Integer.parseInt(br.readLine());
  14. } catch (Exception e) {
  15. throw new RuntimeException(e);
  16. }
  17. }).reduce(Function::andThen).get();
  18. System.out.println("res = " + cont.apply(0));
  19. }
  20. }
  21. }
  22.  
Success #stdin #stdout 0.14s 4386816KB
stdin
1
2
3
stdout
res = 6