It seems get the right answer, but cannot fulfill the last requirement.
package com.codegym.task.task08.task0812;
import java.io.*;
import java.util.ArrayList;
/*
Longest sequence
*/
public class Solution {
public static void main(String[] args) throws IOException {
//write your code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<Integer> nlist = new ArrayList<Integer>();
for (int i = 0; i < 10; i++) {
nlist.add(Integer.parseInt(reader.readLine()));
}
int number = nlist.get(0);
int longcount = 1;
int count = 1;
for (int i = 1; i < 10; ) {
while(nlist.get(i) == number) {
i++;
count++;
}
if (count > longcount) {
longcount = count;
count = 1;
}
number = nlist.get(i);
i++;
}
System.out.println(longcount);
}
}