title: How to count the Strings, numbers, and doubles in a script from the users' input (Scanner) in java?
body: <p>I'm a beginner and I have tried a few different ways from the stuff that I have learned from other people's questions, but I think my problem with the following problem is that I can't figure out the logic of my code. If someone can suggest a solution with explaining the logic of the codes, I would greatly appreciate it.
  I'm supposed to create a method in the format of method() that will prompt the user to enter a script that includes String, numbers, and doubles. The method should count the number of Strings, numbers, and doubles and prints out the list of the string, numbers and doubles. I have got the part that the method prints the list of the strings, numbers and doubles, but it seems I can't get the counter to count them. I have got this so far:</p>
  
  <pre><code> import java.util.Scanner;
   public class Games {
  
      private Scanner input;
  
   public Games() {
  
    input = new Scanner(System.in);
  
   }
  
   public void textParser() {
  
    System.out.println("Enter a Script");
    int intCount = 0;
    int dblCount = 0;
    int strCount = 0;
  
    while(input.hasNext()) {
     if(input.hasNextInt()) {
      int num = input.nextInt();
      System.out.println(num);
      intCount++;
   }else if(input.hasNextDouble()) {
     double value = input.nextDouble();
     System.out.println(value);
     dblCount++;
   }else {
     String oneWord = input.next();
     System.out.println(oneWord);
     strCount++;
   }
  }
  
  System.out.println("Number of integers: " + intCount);
  System.out.println("Number of doubles: " + dblCount);
  System.out.println("Number of strings: " + strCount);
  
  
  }
  
    public static void main(String[] args) {
    Games demo = new Games();
    demo.textParser();
   }
  
  }
  </code></pre>
  
  <p>Example of expected inputs and outputs:</p>
  
  <pre><code> Enter a Script
   32 quick brown foxes jump over 65 lazy dogs and few doubles are 43.3 
   and 76.9
  
   32
   65
   Number of integers: 2
   43.3
   76.9
   Number of doubles: 2
   quick
   brown 
   foxes 
   jump 
   over
   lazy 
   dogs 
   and 
   few 
   doubles 
   are
   and
   Number of strings: 12
  </code></pre>
  
  <p>Actual output:</p>
  
  <pre><code> 32
   65
   43.3
   76.9
   quick
   brown 
   foxes 
   jump 
   over
   lazy 
   dogs 
   and 
   few 
   doubles 
   are
   and
  </code></pre>