Hi,
Here's my code.
I don't understand why my code is wrong.
The output is correct.
In the loop I compare a number to a number, I don't think that I'm comparing object like Strings, don't I?
Anywhay thanks for your hints :-)
Have a nice day
Best regards
package fr.codegym.task.task08.task0812;
import java.io.*;
import java.util.*;
/*
La plus longue séquence
*/
public class Solution {
public static void main(String[] args) throws IOException {
ArrayList<Integer> lista = new ArrayList<Integer>();
BufferedReader inClav= new BufferedReader(new InputStreamReader(System.in));
for(int i=0;i<10;i++){
lista.add(Integer.parseInt(inClav.readLine()));
}
//first step check if list of numbers implemented
//System.out.println(lista);
// test ok
//Creation of one ArrayList to add "sequences found"
ArrayList<Integer> sequences= new ArrayList<Integer>();
// un element = 1 sequence when follow by an equal element counter increase by 1
int counterForSequences= 1;
// Loop througt each element in the list, if not equality break loop and stop counting
for(int i=0;i<lista.size();i++){
for(int j=i+1;j<lista.size();j++){
if(lista.get(j)==lista.get(i)){
counterForSequences++;
}else{break;}
}
// sequences found add to the sequences list
sequences.add(counterForSequences);
//restart counter
counterForSequences=1;
}
//sorting sequences list in reverse
Collections.sort(sequences,Collections.reverseOrder());
//check sequences found by printing out
//System.out.println(sequences);
//initializing variable max with higher sequence found in sequence list
long max = sequences.get(0);
// printing out variable
System.out.println(max);
}
}