title: How to sum integer inputs in Java, and display the results in an array at the end of the program?
body: <p>I am trying to create a "calculator", except it needs to print each element that was used to compose the sum total. This printing of the array elements needs to happen at the end of the program, when the user inputs 0 twice in a row.</p>
  
  <p>Upon entering an input, the integer values will be stored in an array. Once the end of the program has been reached, the contents of this array will be printed. However, if the end of the program has not been reached, the program continues while the user adds consecutive inputs.</p>
  
  <p>Currently, the program will only print one element at a time, instead of every element that was used to calculate the total. I've spent hours trying to debug, and any guidance would be greatly appreciated!</p>
  
  <pre><code>import java.util.*;
  
  public class AddingMachine {
  
  public static void main(String[] args) {
      Scanner scanner = new Scanner(System.in);
      boolean justStarting = true;
      int total = 0;
      int subtotal = 0;
      int input;
      int last = 1;
      int MAXIMUM_NUMBER_OF_INPUTS = 100;
      while (true) {
          input = scanner.nextInt();
          if (input == 0) {
              if (last == 0) {
                  System.out.println("total " + total);
                  return;
              }
              System.out.println("subtotal " + subtotal);
              total += subtotal;
              subtotal = 0;
          }
          subtotal += input;
          last = input;
          int[] numbers = new int[args.length];
          for (int i = 0; i &lt; args.length; i++) {
              numbers[i] = last;
          }
          System.out.println(Arrays.toString(numbers));
      }
  }
  </code></pre>