编写程序ListWords.java实现从键盘输入一个英文句子,统计该句子中英文单词的个数,
将找出所有单词存放到一个数组中。例如:He said,"Ths's not a good idea."则输出
为
共有8个单词:He said ths s not a good idea
这是本人自己写的可是不对,求帮看看
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class ListWords {
public static void main(String[] args) throws IOException {
readkeyboard();
}
public static void readkeyboard() throws IOException {
InputStreamReader str=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(str);
//优化代码
int score = 0;
String st=null;
String[] temp=new String[10];
while(!(st=in.readLine()).equals("quit")){
temp = st.split(" ");
score++;
}
System.out.println("你输入的单词书为"+score+";"+temp);
}
}