title: how to count the number of iterations for loop java
body: <p>I have to implement this method that gives the number of Planets in the array "planeta".</p>
  
  <pre><code>public int size() {
  
      int size=planeta.length-1;
  
      for (int k=planeta.length-1;k&gt;0;k--){
          if (planeta[k].name().equals(noPlanet))
          size--;
      }
      return size;
  
  }
  </code></pre>
  
  <p>It returns the value of "planeta.length-1" and not the ones it's supposed to (for example, I add successfully 2 planets and it always returns the value I give to size when initializing it). What am I doing wrong?</p>
  
  <p>NOTE: I initialize the array "planeta" with NP, that means No Planet. When I add new planets they go to the first free position, starting from 0,in the array "planeta". Please help!!!!! Thank you =)</p>
  
  <p>The addPlanet method:
      public void addPlanet(String planetName, BigInt x, BigInt y, BigInt z) {</p>
  
  <pre><code>    if(!planetExists(planetName) &amp;&amp; !complete()){
  
          SpacePoint newSP= new SpacePoint(x,y,z);
          Planet newPlanet= new Planet(planetName,newSP);
  
          s=this.size();
          planeta[s]=newPlanet;
  
      }
  
  }
  </code></pre>
  
  <p>How i initialize array "planeta":
  private Planet noPlanet=new Planet("NP");</p>
  
  <pre><code>/** 
   * Creates a new Galaxy with no associated Planets and a given name
   * @param name the name of the Galaxy
   */
  public Galaxy(String name) {
  
  
      this.name=name;
  
  
      //if the galaxy has no planets in it,it's array if filled with planet NP-No Planet
      for (int i=0;i&lt;planeta.length;i++)
          planeta[i]=noPlanet;
  
  }
  </code></pre>