0

I tried to make a simple user input word count in java but the output seems to be always one. Any ideas?

package assignment;
import java.util.Scanner;

public class Assignment
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);

        System.out.println("Enter a string: ");
        String str = in.nextLine();
        String [] myString = str.split("\\s+");
        System.out.println("String has " + myString.length + " words.");
    }
}
Darrius
  • 167
  • 1
  • 1
  • 11

0 Answers0