我试图在java中创建一个简单的用户输入字数,但输出似乎总是一个。有什么想法吗?
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.");
}
}