title: Odd number Sequence Replaced by Count
body: <p>I am working on java Program</p>
  
  <p>here is program Question:
  Consider Java Program. 
  It reads integers from the standard input (until it gets a negative number) and 
  puts them into an array. 
  After that it calls processArray on the array, 
  and then prints the contents of the array on standard output.
  in program any sequence of two or more consecutive 
  odd numbers in the array are removed from the array and replaced by a single number representing the length of that sequence. The processArray function/method should modify the array in-place (preferably without creating a new array), and it should return the new length of the modified array.</p>
  
  <p>For example, if these numbers were provided on the standard input:</p>
  
  <pre><code>222
  3
  35
  62
  124
  61
  29
  375
  66
  7
  -1
  </code></pre>
  
  <p>Then the program should print:</p>
  
  <pre><code>222
  2
  62
  124
  3
  66
  7
  </code></pre>
  
  <p>Note that the sequence 3, 35 has been replaced by 2 and the sequence 61, 29, 375 has been replaced by 3. </p>
  
  <p><strong>here is my code</strong>:</p>
  
  <pre><code>import java.util.*;
  import java.io.*;
  
  public class Main {
      public static int processArray(ArrayList&lt;Integer&gt; array) {
          ListIterator&lt;Integer&gt;iterator=array.listIterator();
          while (iterator.hasNext()) {
              Integer integer = (Integer) iterator.next();
              int count=0;
              if (integer%2!=0) {
                  count=count++;
                  iterator.remove();
                  continue;
              }
              if(integer==-1)
                  break;
              else
                  iterator.previous();
              iterator.add(count);
              iterator.next();
  
  
          }
  
          return array.size();
      }
  
      public static void main (String[] args) {
          ArrayList&lt;Integer&gt; arrayList = new ArrayList&lt;Integer&gt;();
          Scanner in = new Scanner(System.in);
          while(in.hasNextInt()) {
              int num = in.nextInt();
              if (num &lt; 0) 
                  break;
              arrayList.add(new Integer(num));
          }
          int new_length = processArray(arrayList);
          for(int i=0; i&lt;new_length; i++)
              System.out.println(arrayList.get(i));
      }
  }
  </code></pre>
  
  <p>My Logic Not Working Properly help to improve logic</p>