導航:首頁 > 編程語言 > 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統計單詞個數相關的資料

熱點內容
資料庫查詢系統源碼 瀏覽:614
php5314 瀏覽:354
完美國際安裝到哪個文件夾 瀏覽:666
什麼app可以掃一掃做題 瀏覽:537
程序員編碼論壇 瀏覽:923
淘點是什麼app 瀏覽:656
中國高等植物pdf 瀏覽:451
51單片機時間 瀏覽:181
後台如何獲取伺服器ip 瀏覽:262
單片機流水燈程序c語言 瀏覽:232
程序員第二職業掙錢 瀏覽:237
運行里怎麼輸入伺服器路徑 瀏覽:837
pythonstepwise 瀏覽:506
劉一男詞彙速記指南pdf 瀏覽:61
php認證級別 瀏覽:364
方舟編譯啥時候推送 瀏覽:1009
php手機驗證碼生成 瀏覽:672
哲學思維pdf 瀏覽:14
凌達壓縮機有限公司招聘 瀏覽:531
weblogic命令部署 瀏覽:35