title: How to read User input word by word from one line with scanner?
body: <p>I am trying to learn java and more specifically scanners. So I tried to create an simple program that gets as input the Student’s code Course1 course1Degree course2 course2Degree and so on until the user inputs the word end. When the user inputs end it’s time to enter the same information for another student. More detailed input is shown below:</p>
  <pre><code>061125 Programming1 6,1 DB1 7,0 Math1 5,5 end[enter]
  071234 DB2 5,5 Java 7,3 end[enter]
  012343 end[enter]
  </code></pre>
  <p>After the user inputs end[enter] the average score of the current student should be displayed.<br />
  The program ends when the user inputs for the Student’s code <code>0000[enter]</code>.</p>
  <p>My problem is that I can never read the correct input what ever I have tried in order to calculate the average score of each student. Also it doesn’t seem to understand when [end] is inputted and after the first input what ever I do when input 0000 the program doesn’t stop. This is what I have till now.</p>
  <pre><code>package test;
  
  import java.util.Scanner;
  
  public class Test {
      
      public static void main(String[] args) {
         readline();
      }
      
      static void readline(){
          Scanner scanner = new Scanner(System.in).useDelimiter(&quot;\\s&quot;);
          String course = &quot;&quot;;
          String code = &quot;&quot;;
          float mark = 0;
          
          System.out.println(&quot;Enter student details: &quot;);
          
          while(!course.equals(&quot;end&quot;)){
              
              code = scanner.nextLine();
              
              if (code.equals(&quot;0000&quot;)) {
                  System.exit(0);
              } else {
                  
                  course = scanner.next();
                  float sum = 0; 
                  while (!scanner.equals(&quot;end&quot;)){
                      mark += scanner.nextFloat();
                      sum += mark;
                      System.out.println(&quot;sum:  &quot; + sum);
                      
                  }
              }
          }
          
          System.out.println(&quot;Final creds: &quot; + &quot; id: &quot;+ code + &quot; course: &quot; + course + &quot; mark: &quot; + mark);
      } 
  }
  </code></pre>