title: Why can't I print a variable that is provided by user inside a loop?
body: <p>I apologize if the answer to this question is so obvious I shouldn't even be posting this here but I've already looked up the error compiling the following code results in and found no explanation capable of penetrating my thick, uneducated skull.</p>
  
  <p>What this program is meant to do is get 2 integers from the user and print them, but I have somehow managed to mess up doing just that.</p>
  
  <pre><code>import java.util.Scanner;
  
  public class Exercise2
  {   
      int integerone, integertwo; //putting ''static'' here doesn't solve the problem
      static int number=1;
      static Scanner kbinput  = new Scanner(System.in);
      public static void main(String [] args)     
      {
          while (number&lt;3){
              System.out.println("Type in integer "+number+":");
              if (number&lt;2)
              {
                  int integerone = kbinput.nextInt(); //the integer I can't access
              }
              number++;
          }
          int integertwo = kbinput.nextInt();
          System.out.println(integerone); //how do I fix this line?
          System.out.println(integertwo);
      }
  }
  </code></pre>
  
  <p>Explanation or a link to the right literature would be greatly appreciated.</p>
  
  <p>EDIT: I want to use a loop here for the sake of exploring multiple ways of doing what this is meant to do.</p>