title: How do I take multiple floats from Scanner and store them separately in Java?
body: <p>I'm writing a program which should take five doubles from user input and return the average of them.</p>
  
  <p>I want the program to take an input like </p>
  
  <pre><code>5.0 8.0 5.0 7.0 5.0
  </code></pre>
  
  <p>and return</p>
  
  <pre><code>6.0
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>import java.util.Scanner;
  
  public class findAverage {
  public static void main(String[] args){
      Scanner keyboard = new Scanner(System.in);
  
      // Initialise the array
      float[] numberArray;
      float total = 0;
  
      // Allocate memory for 5 floats
      numberArray = new float[5];
  
      for(int i = 0; i &lt; 5; i++){
          numberArray[i] = keyboard.nextInt();
          total += numberArray[i];
      }
  
      // Find the average
      float average = total / 5;
      System.out.println(average);
      }
  }
  </code></pre>
  
  <p>Right now, that code takes user input 5 separate times and computes the average. How do I make it so the user can input 5 floats on the same line and have the program find the average?</p>