title: Counting consecutive numbers
body: <p>I am currently stuck on how to count consecutive numbers inputted by the user. I am trying to do <code>a=lastvariable</code> but <code>lastvariable</code> stays 0. I know about variable scope, but how do I change <code>a=lastvariable</code>?</p>
  
  <hr>
  
  <pre><code>import java.util.Scanner;
  
  public class Test {
      public static void main(String[]args){
  
          Scanner scan = new Scanner(System.in);
  
          System.out.print("Give a positive #: ");
          int input = scan.nextInt();
          int consecutive= 0;
          int lastvariable=0;
  
  
          while(input&gt;0){
              System.out.print("Give a positive #: ");
              int a = scan.nextInt();
              if(a==lastvariable)
                   consecutive++;
              if (a&lt;0)
                  input = 0;
              a = lastvariable;
          }
          System.out.println("Consecutive #'s: " + consecutive);
      }
  </code></pre>