SHARE
TWEET

Untitled

a guest May 13th, 2016 125 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3. import java.util.function.Predicate;
  4. import java.util.stream.IntStream;
  5.  
  6. public class FindEvenOrOdd {
  7.     public static void main(String[] args) {
  8.         Scanner sc = new Scanner(System.in);
  9.         int [] bounds= Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
  10.         int [] arr = IntStream.range(bounds[0],bounds[1] + 1).map(i -> i++).toArray();
  11.         String command = sc.nextLine();
  12.         switch(command){
  13.             case "odd":  Arrays.stream(arr).filter((i) ->!isEven.test(i))
  14.                         .forEach(odd -> System.out.print(odd + " "));
  15.                 break;
  16.             case "even": Arrays.stream(arr).filter((i) ->isEven.test(i))
  17.                         .forEach(even -> System.out.print(even + " "));
  18.                 break;
  19.         }
  20.     }
  21.     private static Predicate<Integer> isEven = (i) -> i%2==0;
  22. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top