title: How to sum elements of a stack
body: <pre><code>import java.util.*;
  
  public class multiple {
      public static int userNumber;
      public static int userChoice;
      static Stack&lt;Object&gt; stack = new Stack&lt;Object&gt;();
      static int[] list = new int[100];
  
      public static void main(String[] args) {
          introduction();
          multiple();
          printStack(stack);
  
      }
  
      public static void introduction() {
          Scanner input = new Scanner(System.in);
  
          System.out.print("Welcome to the program, please enter the number  less than 100 that you would like "
                          + "to find whoes number \nbelow have muliples of 3 and 5: ");
          userNumber = input.nextInt();
  
          System.out.println();
  
          // System.out.println("Ok, now that youve entered," + userNumber +
          // " we will find out which numbers of you number are three and five. "
          // +
          // "would you like the result published as a:\n 1.alist \n 2.A sum of the result \n 3.Or both?");
          // userChoice = input.nextInt();
  
          // if (userChoice &gt;=1 &amp;&amp; userChoice &lt;=3)
          // System.out.println( "The Computer will now program for" +
          // userChoice);
  
          // else
          // System.out.println("incorrect entry for menu. Please try again");
  
      }
  
      public static void multiple() {
          for (int i = 1; i &lt; userNumber; i++) {
              if (i % 3 == 0 || i % 5 == 0) {
                  stack.push(i);
              }
          }
  
      }
  
      // public static addElementsofstac
  
      private static void printStack(Stack&lt;Object&gt; s) {
          if (s.isEmpty())
              System.out.println("You have nothing in your stack");
          else
              System.out.println(s);
      }
  
  }
  </code></pre>
  
  <p>I am trying to make a simple program that will take input for a user, find out the multiples of 3 &amp; 5, then return the sum of the multiple. I have all the multiples discovered. I have a hunch that i need to convert the stack to an array. if so, would i just use stack.toArray()? then i would add them in a for loop?</p>