title: Saving java variables
body: <p>I am working on an assignment and am unable to do a function because of this issue. </p>
  
  <p>At the very beginning of the program I created a variable </p>
  
  <pre><code>int initial = Keyboard.nextInt() (obviously user input)
  </code></pre>
  
  <p>The program then goes into a loop in which the value of 'initial' is altered many times. However at the end of the program, when we exit the loop, I need to use the new 'initial' value and also the exact value that the user initially entered.</p>
  
  <p>I am having difficulty getting the program to find the initial value because after exiting the loop any time I try to call on the 'initial' variable I only get the altered number not the first one the user entered. Help as to how I can solve this issue would be appreciated, thanks. </p>
  
  <pre><code>public class Question3 {
  
      public static void main(String[] args) {
  
  
                   //declare scanner 
                  Scanner keyboard = new Scanner (System.in);
  
  
                  //initial amount
                  System.out.println("Enter the initial amount: ");
                  int initial = keyboard.nextInt();
  
                  int numItems = 0;
                  double assets = 0;
                  int originalPrice=initial; 
                  double spending = originalPrice-assets;
  
  
                  if(initial&lt;=10)
                  {
                      System.out.println("Please save money and come back later!!");
                      numItems=1;
                      spending=0.0;
                  }
                  else 
                      while (initial &gt; 10 )
                  {   
                      System.out.println("Do you want to make purchases (Y/N)? ");
                      char c = keyboard.next().charAt(0);
                  if (c == 'Y')
                      {
                          System.out.println("Please enter the price of the item = ");
                      }
  
                  else 
                  {
                          System.out.println("Lack of desire of Mr.Toto");
                          break;
                  }
  
                  int price = keyboard.nextInt();
  
                  if (initial-price&gt;=10)
                      {
                          System.out.println("A purchase is accepted");
                          initial-=price;
                          assets=initial-price;
                          numItems++;
                      }
  
                  else
                      {
                          System.out.println("Insufficient assets!!");
                          System.out.println("Please enter the price of the item = ");
                      }
                  if(numItems==10)
                  {
                      System.out.println("Maximal number of purchases reached");
                      break;
                  }
  
  
                  }
  
                  //displaying the summary of mr totos purchases 
                  System.out.println("-------------------------------------------");
                  System.out.println("Here is a summary of Mr.Toto's purchases.");
                  System.out.println("-------------------------------------------");
                  System.out.println("Number of items     Assets      Spending");
                  System.out.println("    "+numItems+"                "+assets+"   " +"       "+spending);
                  }
      }
  </code></pre>