title: How to use what the user input for an array size from the main method?
body: <p>I'm trying to create a program that measures the time it takes for each sorting algorithm to sort random integers in an array. The problem is in my main class I ask the user to input what the size of the array should be. However, I'm trying to pass this number "arraySize" into another class. </p>
  
  <p>For now, I set the size of the array as 50.</p>
  
  <p>So, the program should work by taking in array with a size of input.next() and then populates the array with random integers. It then sorts the array and measures the time. </p>
  
  <p>This is my main: </p>
  
  <pre><code>  public static void main(String[] args)
        { 
  
        // final int was set earlier in the assignment to 50. Therefore
        //the program will only take an answer for a size n of 50.
  
        System.out.println("Please enter the size of array:");
        Scanner input = new Scanner(System.in); 
        int arraySize =input.nextInt();    
  
          initValues();
          printValues();
          System.out.println("values is sorted: " + isSorted());
          System.out.println();
  
          // make call to sorting method here (just remove //)
  
           /**long startTime = System.nanoTime();
           long total = 0; 
           selectionSort(); 
           long stopTime = System.nanoTime();
           long elapsedTime = stopTime-startTime;
           */
  
           long startTime = System.nanoTime();
           long total = 0;
           bubbleSort();
           long stopTime = System.nanoTime();
           long elapsedTime = stopTime-startTime;
  
          printValues();
          System.out.println("values is sorted: " + isSorted());
          System.out.println();
          System.out.println("The time it took to sort was: " +elapsedTime); 
        }
       }
  </code></pre>
  
  <p>This is in same class as my main: </p>
  
  <pre><code>public class Sorts
  {
    static  int SIZE =50;            // size of array to be sorted
    static int[] values = new int[SIZE];   // values to be sorted
  
    static void initValues()
    // Initializes the values array with random integers from 0 to 99.
    {
      Random rand = new Random();
      for (int index = 0; index &lt; SIZE; index++)
        values[index] = Math.abs(rand.nextInt()) % 100;
    }
  
    static void selectionSort()
    // Sorts the values array using the selection sort algorithm.
    {
      int endIndex = SIZE - 1;
      for (int current = 0; current &lt; endIndex; current++)
        swap(current, minIndex(current, endIndex));
    }
  </code></pre>
  
  <p>Why can't I replace SIZE with arraySize? Is there a way where I can declare SIZE as my input.nextInt() in my main method? If I do that, it still populates the array with 50 random integers.  </p>