apparently my code is good up to line 36. I manage to form the list2. But then my program doesn't work for numbers above 127 when I search for the maximum value of my list. could someone please explain why?
package fr.codegym.task.task08.task0812;
import java.io.*;
import java.util.ArrayList;
/*
La plus longue séquence
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader lecteur = new BufferedReader(new InputStreamReader(System.in));
ArrayList<Integer> liste = new ArrayList<Integer>();
for( int i = 0; i < 10; i++){
liste.add(Integer.parseInt(lecteur.readLine()));
}
ArrayList<Integer> liste2 = new ArrayList<Integer>();
int l = 1;
for (int j = 0; j < liste.size() - 1; j++) {
if (liste.get(j) == liste.get(j + 1)) {
l++;
if ((liste.get(liste.size() - 1) == liste.get(liste.size() - 2)) && (j == liste.size() - 2))
liste2.add(l);}
if(liste.get(j) != liste.get(j + 1)) {
liste2.add(l);
if ((liste.get(liste.size() - 1) != liste.get(liste.size() - 2)) && (j == liste.size() - 2)){
liste2.add(1);}
l = 1;
}
}
int max =liste2.get(0);
for(Integer c : liste2 ){
if(c>max){
max=c;
}
}
System.out.println(max);
}
}