package pl.codegym.task.task08.task0812;
import java.io.*;
import java.util.ArrayList;
/*
Najdłuższa sekwencja
*/
public class Solution {
public static void main(String[] args) throws IOException {
//tutaj wpisz swój kod
int repeat=1;
ArrayList<Integer> integers = new ArrayList<>();
ArrayList<Integer> times = new ArrayList<>();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for(int i=0; i<5; i++)
{
integers.add(Integer.parseInt(reader.readLine()));
}
for(int i=1; i< integers.size(); i++)
{
if(integers.get(i)== integers.get(i-1))
{
repeat++;
} else if(!(integers.get(i)== integers.get(i-1)))
{
continue;
}
if(i==integers.size())
{
times.add(repeat);
}
}
int max = 1;
for(int i=0; i< times.size(); i++)
{
if(times.get(i)>max)
{
max = times.get(i);
}
if(i==(times.size()-1)){
System.out.println(max);
}
}
}
}
Can't see what's wrong
Dyskutowane
Komentarze (1)
- Popularne
- Najnowsze
- Najstarsze
Musisz się zalogować, aby dodać komentarz
Nicolas
14 lutego, 13:44
Hello there.
You need to add 10 integers from console in your ArrayList, not 5.
Your "else if" condition is already checked by your first "if", so it's not useful.
Your last "if" is always false. "i" can not equals your array size because of "for(int i=1; i< integers.size(); i++)" which means that your "times" array size is always going to be 0 as nothing can be added inside and thus, the last part of your code will never be used :) !
0