Please excuse all the comments.
The program produces the right result, I believe.
package com.codegym.task.task08.task0812;
import java.io.*;
import java.util.*;
import static java.lang.System.out;
/*
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.
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader a = new BufferedReader(new InputStreamReader(System.in));
List<Integer> list = new ArrayList<>(Arrays.asList(1, 2, 2, 2));
Map<Integer, Integer> NumbersAndStreaks = new TreeMap<>();
//Random rnd = new Random();
// Initialize array from command input. Random number generator used for debugging
/*
for (int i = 0; i < 10; i++) {
Integer number = rnd.nextInt(7);
list.add(number);
}
*/
for (int i = 0; i < 10; i++) {
list.add(Integer.parseInt(a.readLine()));
}
Integer counter = 1;
// Iterate from position 0 to the penultimate place
for (int i = 0; i < list.size() - 1; i++) {
// If the current number in the list does not exist in the map:
// add it to the map with streak of 1
//out.print("["+i+"]: Pointer = "+list.get(i));
//out.print(". Exists in map? "+NumbersAndStreaks.containsKey(list.get(i))+"\n");
NumbersAndStreaks.putIfAbsent(list.get(i), 1);
// If the next number is the same as the current number
if (list.get(i+1).equals(list.get(i))) {
//out.println("The next number is the same.");
counter++;
// And the current streak is higher than the last highest string,
if (NumbersAndStreaks.get(list.get(i)) <= counter) {
// Assign the current streak to the map
NumbersAndStreaks.put(list.get(i), counter);
//out.println("Streak is: "+NumbersAndStreaks.get(list.get(i)));
}
} else {
// If streak is broken:
// Reset counter
counter = 1;
}
}
int maxValue = Collections.max(NumbersAndStreaks.values());
//int key = 50;
/*
//iterate through the map to get the key that corresponds to the maximum value in the Hashmap
for (Map.Entry<Integer, Integer> entry : NumbersAndStreaks.entrySet()) { // Iterate through hashmap
if (entry.getValue() == maxValue) {
key = entry.getKey(); // this is the key which has the max value
break;
}
}
*/
//out.println(list);
//out.println(NumbersAndStreaks);
out.println(maxValue);
}
}