導航:首頁 > 編程語言 > java統計單詞個數

java統計單詞個數

發布時間:2023-03-22 05:47:09

1. java統計單詞的個數

import java.util.Scanner;

public class Test40031 {
public static void main(String []args ){
int ri, repeat,count, word,i;
String line;
char c;
Scanner in=new Scanner(System.in);
repeat=(in.nextLine()).charAt(0)-'0'; //輸入repeat
for(ri=1; ri<=repeat; ri++){
line=in.nextLine(); //輸入一行字元
/*---------*/
count=Count(line);
System.out.println(count);
}
}
public static int Count(String str){
String[] str1=str.split(" ");
int count=str1.length;
return count;
}
}

2. 用java編寫應用程序,分析字元串,分別輸出字元串的單詞,並統計單詞個數

public class StringTest {x0dx0a public static void main(String[] args) {x0dx0a //定義一個測試字元串x0dx0a String testStr = "this is a test string";x0dx0a x0dx0a //將該字元串按空格分解辯碰歲成單吵嫌詞數組x0dx0a String[] words = testStr.split(" ");x0dx0a x0dx0a //輸出單詞個數x0dx0a System.out.println("該字元串一共有" + words.length + "個單詞!");x0dx0a x0dx0a //攜睜輸出每一個單詞x0dx0a for (int i = 0; i < words.length; i++) {x0dx0a System.out.println("該字元串的第" + (i+1) + "個單詞是:" + words[i]);x0dx0a }x0dx0a }x0dx0a}

閱讀全文

與java統計單詞個數相關的資料

熱點內容
sql加密身份證號解碼 瀏覽:161
解壓玩法視頻 瀏覽:463
蘋果xls如何設置加密 瀏覽:204
湖北廣電dns的伺服器地址是多少 瀏覽:527
php獲取原始數據 瀏覽:247
pic單片機如何編程 瀏覽:892
javabyte寫文件 瀏覽:323
java獲取類包名 瀏覽:892
ftp命令編碼格式 瀏覽:299
程序員那麼可愛陸離穿正裝 瀏覽:171
源碼的賬號密碼在哪個文件 瀏覽:442
如何在中國農業銀行app綁定銀行卡 瀏覽:995
shopnum1多用戶商城系統源碼 瀏覽:749
紅包廣告平台源碼 瀏覽:775
硬碟格式化時用的dos命令是 瀏覽:942
找人緩解壓力 瀏覽:941
iphone的pdf 瀏覽:354
90壓縮餅干怎麼吃 瀏覽:671
php教材下載 瀏覽:918
什麼解壓密碼最好 瀏覽:593