i get this message :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.
when i test it , everything works fine .
package com.codegym.task.task08.task0812;
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
/*
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.
Example for the list 2, 4, 4, 4, 8, 8, 4, 12, 12, 14:
3
The value is 3, because the longest sequence of repeating numbers is three fours.
Requirements:
1. The program must display a number on the screen.
2. The program should read values from the keyboard.
3. In the main method, declare an ArrayList variable with Integer elements and immediately initialize it.
4. The program should add 10 numbers to the collection in accordance with the conditions.
5. The program should display the length of the longest sequence of repeating numbers in the list
*/
public class Solution {
public static void main(String[] args) throws IOException {
Scanner scan = new Scanner(System.in);
ArrayList<Integer>list = new ArrayList<Integer>();
for (int i =0; i<10;i++){
list.add(scan.nextInt());
}
int countA=1;
int countB=1;
for (int i=0;i<list.size()-1;i++){
if (list.get(i).equals(list.get(i+1))){
countA++;
}
if(countB<=countA){
countB=countA;
countA=1;
}
}
System.out.println(countB);
}
}