Dan array. Find the longest sequence of consecutive elements in the array = 0, count their number, find out the index of the first 0 in this sequence.
Ex .: 9 10 8 0 0 3 5 6 0 0 0 1 3 the answer will be 3 and 9 (element).
What am I doing wrong?
It counts only the number of the first sequence of zeros. In addition, I decided to first deal with finding the correct sequence, so I did not consider the index yet:
public static void main(String[] args) { int s=0;//счетчик сколько нулей подряд int k=0;//количество нулей подряд int x[] = {2, 2, 0, 0, 0, 5, 1, 0, 0, 0, 0} ; k=s; {s=0; for( int i=0; i<x.length; i++) if(x[i]==0) s=s+1; else if(s>k) k=s; System.out.print(k); } } }