title: variable array length inside method
body: <p>I need to solve an exercise that work like the following:</p>
  
  <ol>
  <li>A user start adding integers into an array;</li>
  <li>When he want to stop adding numbers, he should type <code>-1</code>;</li>
  <li>After typing <code>-1</code>, a message appears where it display the numbers added, with the <code>count</code> of them</li>
  </ol>
  
  <p>So if he entered: <code>1 8 6 9 -1</code></p>
  
  <p>The result would be:</p>
  
  <p>Numbers entered are: <code>1 8 6 9 -1</code> And the count is <code>5</code>.</p>
  
  <p>I tried to write the code:</p>
  
  <pre><code>import java.util.*;
  import java.lang.*;
  import java.io.*;
  
  /* Name of the class has to be "Main" only if the class is public. */
  class exercice
  {
      public static void main (String[] args) throws java.lang.Exception
      {
          readNumbers();
      }
  //No parameters inside: just readNubers()
      public static void readNumbers()
      {
          int[] num = new int[n];
          int x = 0;
          while(x!=-1)
          {
              for(int i=0; i&lt;n; i++)
              {
                  System.out.println("Enter a number");
                  Scanner scan = new Scanner(System.out);
                  x = scan.nextInt();
                  num[i]=x;
              }
          }
          for(int j = 0; j&lt;num.length; i++)
          {
              System.out.println(num[i]);
              System.out.println("The total of entered numbers is: "+num.length);
          }
      }
  }
  </code></pre>
  
  <p>But, I am still stuck at how to define a variable array length, without using ArrayList. SO I need to solve it like this code above.</p>
  
  <p>In out course, we have an example where we can define an array with unknown length like this:</p>
  
  <p><code>method_name(int ...a)</code> but can't know how to use it.</p>