導入Java . io . io exception;
導入Java . io . inputstreamreader;
公共舞蹈課
公共靜態void main(String[] args){
String str = new String();
System.out.print("請輸入英文句子:");
嘗試{
buffered reader br = new buffered reader(new InputStreamReader(system . in));//獲取鍵盤輸入
str = br . readline();
}catch(IOException e){
e . printstacktrace();
}
string[]s = str . split(" ");//轉換為數組
System.out.println("妳輸入的句子* *有單詞"+s.length+"個");//s.length獲取數組長度。
}
}
//這個程序只能得到壹句話的字數。