title: Java. Array, save previous values
body: <p>Cant figure out how to do this thing. I need to store and count number of "jumps" and direction of "jump" in array. 
  Console has to display something like this:</p>
  
  <blockquote>
    <p>: Jump 1, direction Left</p>
    
    <p>: Jump 2, direction Right</p>
  </blockquote>
  
  <p>In my code below, when I print array elements,  <code>int jump</code> always equals to 0;</p>
  
  <p>I tried many variations, sometimes I got (for example):</p>
  
  <pre><code>jump();
  
  jump();
  
  jump();
  
  jump();
  </code></pre>
  
  <p>And it prints: <code>{0,0,0,4}</code> , instead of <code>{1,2,3,4};</code></p>
  
  <pre><code>public class Jump {
  int jump;
  String direction;
  Jump[] jumpArray = new Jump[100];
  int storeJump;
  String storeDirection;
  
  public void jump() {
      jump++;
      if (jump &gt; 50) {
          System.out.println("need a rest");
          return;
      } else {
  
          for (int i = 0; i &lt; jumpArray.length; i++) {
              jumpArray[i] = new Jump();
          }
      }
      jumpArray[jump].storeJump = jump;
      jumpArray[jump].storeDirection = direction;
  
  }
  
  public static void main(String[] args) {
      Jump jumper = new Jump();
      jumper.jump();
      jumper.jump();
  
      for (int i = 0; i &lt; jumper.jump; i++) {
          System.out.println(jumper.jumpArray[i].jump);
  
      }
  
  }
  
  }
  </code></pre>