The Error 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.
My Code:
public static void main(String[] args) throws IOException {
//write your code here
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
int maxCount = 1;
int count = 1;
ArrayList<Integer> numList = new ArrayList<Integer>();
for(int i = 0; i<10;i++){
numList.add(Integer.parseInt(r.readLine()));
}
for(int i = 0;i<9;i++){
loop2:
for(int j = i+1;j<10;j++){
if(numList.get(i) == numList.get(j)){
count++;
if(count>maxCount){
maxCount=count;
}
}
else{
count = 1;
break loop2;
}
}
}
System.out.println(maxCount);
}
Please Help!package com.codegym.task.task08.task0812;
import java.io.*;
import java.util.ArrayList;
import java.util.*;
/*
Longest sequence
*/
public class Solution {
public static void main(String[] args) throws IOException {
//write your code here
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
int maxCount = 1;
int count = 1;
ArrayList<Integer> numList = new ArrayList<Integer>();
for(int i = 0; i<10;i++){
numList.add(Integer.parseInt(r.readLine()));
}
for(int i = 0;i<9;i++){
loop2:
for(int j = i+1;j<10;j++){
if(numList.get(i) == numList.get(j)){
count++;
if(count>maxCount){
maxCount=count;
}
}
else{
count = 1;
break loop2;
}
}
}
System.out.println(maxCount);
}
}