I ran the code by putting my longest sequence in the end and it seems to work perfectly fine. Pls help.
I see this recommendation from the mentor for the last requirement-
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.
package com.codegym.task.task08.task0812;
import java.io.*;
import java.util.*;
/*
Longest sequence
1. Create a list of numbers.
2. Use the keyboard to add 10 numbers to the list.
3. Display the length of the longest sequence of repeating numbers in the list.
*/
public class Solution {
public static void main(String[] args) throws IOException {
//write your code here
ArrayList<Integer> list = new ArrayList<Integer>();
Scanner sc = new Scanner(System.in);
int cou = 1;
int temp = 1;
for (int i=0; i<10; i++) {
int readInt = sc.nextInt();
list.add(readInt);
}
for (int i=0; i<=10; i++) {
// int temp = list.get(i);
if (cou > temp) {
temp = cou;
cou = 0;
}
for (int j=i+1; j<10; j++) {
if (list.get(i).equals(list.get(j))) {
cou ++;
}
else break;
}
}
System.out.println(temp);
}
}