SHARE
TWEET

Untitled

a guest May 13th, 2016 66 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.IntPredicate;
  4. import java.util.function.Predicate;
  5. import java.util.stream.IntStream;
  6.  
  7. public class FindEvenOrOdd {
  8.     public static void main(String[] args) {
  9.         Scanner sc = new Scanner(System.in);
  10.         int [] bounds= Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
  11.         int [] arr = IntStream.range(bounds[0],bounds[1] + 1).map(i -> i++).toArray();
  12.         String command = sc.nextLine();
  13.         switch(command){
  14.             case "odd": arr = Arrays.stream(arr).filter(isOdd).toArray();
  15.                 break;
  16.             case "even": arr = Arrays.stream(arr).filter(isEven).toArray();
  17.                 break;
  18.         }
  19.         Arrays.stream(arr).forEach(element -> System.out.print(element + " "));
  20.     }
  21.     private static IntPredicate isEven = (i) -> i%2==0;
  22.     private static IntPredicate isOdd = (i) -> i%2==1;
  23. }
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
 
Top