字数:用户定义

时间:2015-10-26 16:55:44

标签: java count word

我试图在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.");
    }
}

0 个答案:

没有答案