title: Java Array Beginner Menu
body: <p>I am trying to make a menu where the user has an option to add numbers to the array and technically they can add how many values they want but one at a time. So when they pick to add a number to the array, they would enter one number, and then it would prompt the menu again. I'm having trouble with adding the number to the array &amp; displaying the array. I'll add two numbers &amp; display the array to look at it &amp; I get 30000000000000000000000000000000000000000000000000000000000 because of my array max, I think. all I want is for it to add only the digits I enter to the array when I want to enter it &amp; continue to do that from there.</p>
  
  <p>how exactly would I fix that though? I want the user to have complete control to how big the array will be, etc.</p>
  
  <pre><code>import java.util.*;
  
  public class arrayMenu
  {
     public static void main(String[] args)
     {
        Scanner kb;
        int option;
        kb = new Scanner(System.in);
        option = menu(kb);
        int[] myArray = new int[99];
  
        while (option != 6)
        {
           switch (option)
           {
              case 1:
                 myArray = newNum(kb, myArray);
                 break;
              case 2:
                 display(myArray);
                 break;
              case 3:
  
                 break;
              case 4:
  
                 break;
              case 5:
  
                 break;
           }
           option = menu(kb);
        }
        if (option == 6)
        {
           System.out.println();
           System.out.println("Thank you. Have a nice day.");
        }
     }
     public static int menu(Scanner kb)
     {
        int myOption = 0;
        while (myOption != 1 &amp;&amp; myOption != 2 &amp;&amp; myOption != 3 &amp;&amp; myOption != 4 &amp;&amp; myOption != 5 &amp;&amp; myOption != 6)
        {
           System.out.println();
           System.out.println("Please select from the following menu choices.");
           System.out.println();
           System.out.println("1. Add a number to the array \n2. Display the mean \n3. Display the median \n4. Print the array to the screen \n5. Print the array in reverse order \n6. Quit");
           System.out.println();
           System.out.print("Choice --&gt; ");
           myOption = kb.nextInt();
           kb.nextLine();
           if (!(myOption == 1 || myOption == 2 || myOption == 3 || myOption == 4 || myOption == 5 || myOption == 6))
              System.out.println("I am sorry that is an invalid menu choice.\nPlease try again"); 
        }
        return myOption;
     }
     public static int intNum(Scanner kb)
     {
        int num = -1;
        while (!(num &gt;= 0))
        {
           System.out.print("Please enter a non-negative integer --&gt;");
           num = kb.nextInt();
  
           if (num &lt; 0)
              System.out.print("I am sorry that is not a non-negative integer.  \n");
        }
        return num;
     }
     public static int[] newNum(Scanner kb, int[] array) 
     {  
        for (int i = 0; i &lt; 1; i++) 
        { 
           System.out.print("Please enter a number:"); 
           array[i] = kb.nextInt(); 
        } 
        return array;
     }
     public static void display(int[] array)
     {
        for (int myValue : array)
        {
           System.out.print(myValue);
        }
     }
  
  }
  </code></pre>