Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Exam;
- import java.util.Scanner;
- public class LongestSequence {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- String line = input.nextLine().replace(" ", "").replace("(", "")
- .replace(")", " ");
- System.out.println(line);
- String[] arrStr = line.split(" ");
- int[] arr = new int[arrStr.length];
- for (int i = 0; i < arrStr.length; i++) {
- arr[i] = Integer.parseInt(arrStr[i]);
- }
- int bestSum = 1;
- int sum = 1;
- boolean even = false;
- boolean odd = false;
- for (int i = 0; i < arr.length - 1; i++) {
- if (arr[i] % 2 == 0) {
- sum = 1;
- even = true;
- odd = false;
- } else {
- sum = 1;
- even = false;
- odd = true;
- }
- for (int j = i + 1; j < arr.length; j++) {
- if (even) {
- sum++;
- even = false;
- odd = true;
- }else if (odd) {
- sum++;
- even = even;
- odd = false;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement