title: How to store the data on every instance of do-while loop in Java?
body: <p>I am currently studying Java and I need to add the values of every instance in my do-while loop. Is there some way to store the values so it won't be overwritten every loop?</p>
  
  <pre><code>import java.util.Scanner;   
  
  class Main{
      public static void main(String[] args){
      Scanner input = new Scanner(System.in);
  
      char userChar;
  
      do {
  
          System.out.println("Apples are $10");
          System.out.println("How many do you want?");
          int itemQty = input.nextInt();
  
          System.out.println("Do you wish to buy more? (y/n)");
          userChar = input.next()charAt(0);
  
      } while (userChar == 'y');
  
      // all values entered by the user needs to be added 
      System.out.println("The total is: $" + (itemQty*10)); 
  
  }
  </code></pre>
  
  <p>}</p>