title: Create an array based on a range of values given by the user
body: <p>What I'm trying to do is create an array based on values given by the user. The user has to give the length of the array plus the max and min values. I've managed to get the program to the point where it does output the correct amount of values (the correct length), but it just keeps outputting the exact same number (which is the max and min added). Based on research I did I tried converting them to a string so that wouldn't happen, but it still isn't working correctly. I've tried a couple of different methods including: Integer.toString, String.valueOf, and creating a whole new string. Any help would be greatly appreciated. Here's the code so far:</p>
  
  <pre><code>   public static void main(String[] args) {
  
      //Create a Scanner object
      Scanner input = new Scanner(System.in);
  
      //Ask the user to enter the length of the array
      System.out.println("Please enter the length of the array:");
      int arraylength = input.nextInt();
  
      //Ask the user to enter a max value
      System.out.println("Please enter the max value:");
      int max = input.nextInt();
  
      //Ask the user to input the minimum value
      System.out.println("Please enter the min value:");
      int min = input.nextInt();
  
      //Initialize the array based on the user's input
      double [] userArray = new double[arraylength];                            
  
     /**
      *The program comes up with random numbers based on the length
      *entered by the user. The numbers are limited to being between
      *the minimum and maximum value.
      */
      for (int i = min; i &lt; userArray.length; i++) {
          userArray[i] = Math.random() * max; 
  
      }
  
      //This code is supposed to sort the array and print out all of the numbers in   order,
      //with minimum in the beginning and max in the end.
      for (int i = 0; i &lt; userArray.length; i++) {
  
          selectionSort(userArray);
  
              Integer.toString(min);
              Integer.toString(max);
  
              System.out.println(min + userArray[i] + max);   
      }
  
      //This code uses the method average to find the average
      average(userArray);
  
   //Close Scanner
   input.close();
      }
  
  public static double average(double[] data) {
  
      double sum = 0; 
      for (int i = 0; i &lt; data.length; i++) {
          sum = sum + data[i];
  
      }
  
      double average = sum / data.length;
  
      return average;
  
  }
  
  public static void selectionSort(double[] list) {
      for (int i = 0; i &lt; list.length - 1; i++) {
          //Find the minimum in the list[i...list.length-1]
          double currentMin = list[i];
          int currentMinIndex = i;
  
          for (int j = i + 1; j &lt; list.length; j++) {
              if (currentMin &gt; list[j]) {
                  currentMin = list[j];
                  currentMinIndex = j;                    
              }
          }
  
          //Swap list[i] with list[currentMinIndex] if necessary
          if (currentMinIndex != i) {
              list[currentMinIndex] = list[i];
              list[i] = currentMin;
          }
  
  
      }
  }
  
  
  }
  </code></pre>
  
  <p>Now, after I added that bit with the average calculation, the program did work once, though it did not compute the average (so it just created an array with min and max at the ends, sorted). It appears to be a fluke, because this is the exact same code and it hasn't done that since. Though maybe the average code somehow affected the rest? </p>