In testing with the sequence 1,2,3,4,4,5,5,5,5,5 the displayed number was correct for the longest set of entered numbers - 5. but the program states that i should check that it returns correctly if the sequence of longest repeated numbers is located at the end of the list.
So im a bit confused.
Anyone able to offer any guidance please?
package com.codegym.task.task08.task0812;
import java.io.*;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;
/*
Longest sequence
*/
public class Solution {
public static void main(String[] args) throws IOException {
//write your code here
ArrayList<Integer> intlist = new ArrayList<>();
Scanner reader = new Scanner(System.in);
for(int i = 0; i < 10; i++){
intlist.add(reader.nextInt());
}
int maxrepeat = 1;
int currseq = 0;
for (int i = 0; i < 9; i++) {
if (intlist.get(i).equals(intlist.get(i + 1))) {
currseq++;
if (currseq > maxrepeat)
maxrepeat = currseq;
}
}
System.out.println(maxrepeat);
}
}