Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Scanner;
- import java.util.stream.IntStream;
- public class functional1_Lab_6Find_Evens_Or_Odd {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int[] range = Arrays.stream(scanner.nextLine().split(" "))
- .mapToInt(Integer::parseInt).toArray();
- int startRange = range[0];
- int endRange = range[1];
- String data = scanner.nextLine();
- if (data.equals("odd")) {
- IntStream.range(startRange, endRange + 1).filter(f -> f % 2 != 0).forEach(e -> System.out.printf("%d ", e));
- }else {
- IntStream.range(startRange, endRange + 1).filter(f -> f % 2 == 0).forEach(e -> System.out.printf("%d ", e));
- }
- // System.out.println(matcher.toString().replaceAll("[\\[\\],]", ""));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement