Code compiles properly and gets the right output, but it still produces the "Be sure that the length of the longest sequence is calculated correctly when it is located at the end of the list of entered numbers" note and fails the last point. Anyone see what I'm missing?
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 {
BufferedReader kb = new BufferedReader(new InputStreamReader(System.in));
ArrayList<Integer> lst = new ArrayList<Integer>();
for (int i = 0; i < 10; i++)
{
lst.add(Integer.parseInt(kb.readLine()));
}
int longest = 0, current = 0;
for (int i = 0; i < 10; i++)
{
try
{
if (lst.get(i).equals(lst.get(i + 1)))
{
current++;
}
}
catch (Exception e)
{
if (longest < current)
{
longest = current;
}
}
}
if (longest == 0)
System.out.println(1);
else
System.out.println(longest);
}
}