亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

文本分析程序,漢字計數為什么不對啊- -

文本分析程序,漢字計數為什么不對啊- -

killio 2017-06-12 22:24:51
package java_homework;import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.Arrays;import java.util.regex.Matcher;import java.util.regex.Pattern;public class testBeta { public static void main(String[] args) throws IOException { File fleInput=new File("D:\\zed.txt"); ? ? ? ?FileInputStream fis=new FileInputStream(fleInput); ? ? ? ?InputStreamReader fsr=new InputStreamReader(fis); ? ? ? ?BufferedReader br=new BufferedReader(fsr); ? ? ? ?? ? ? ? ?int intAlpha,intNum,intOther,intChinese; ? ? ? ?? ? ? ? ?intAlpha=intNum=intOther=intChinese=0; ? ? ? ?int intChar=br.read(); ? ? ? ?while (intChar!=-1){ ? ? ? ? ? ?if ((intChar>=0x41 && intChar<=0x5A) || (intChar>=0x61&& intChar<=0x7A)){ ? ? ? ? ? ? ? ?intAlpha++; ? ? ? ? ? ?}else if (intChar>=0x30 && intChar<=0x39){ ? ? ? ? ? ? ? ?intNum++; ? ? ? ? ? ?}else if (intChar>=0 && intChar<=127) ? ? ? ? ? ?{ ? ? ? ? ? ? ? ?intOther++; ? ? ? ? ? ?}else{ ? ? ? ? ? ? ? ?intChinese++; ? ? ? ? ? ?} ? ? ? ? ? ?intChar=br.read(); ? ? ? ?} ? ? ? ?? ? ? ? ?fis.close(); ? ? ? ?? ? ? ? ?System.out.println("Alpha count=" + intAlpha); ? ? ? ?System.out.println("Number count=" + intNum); ? ? ? ?System.out.println("Other count=" + intOther); ? ? ? ?System.out.println("Chinese count=" + intChinese); } }
查看完整描述

1 回答

?
呦呦米

TA貢獻90條經驗 獲得超59個贊

編碼方式不同貌似占位的數量不一樣

查看完整回答
反對 回復 2017-06-13
  • killio
    killio
    但是他一個漢子輸出3個,兩個漢字輸出5個- -就算是輸出字節數我也不知道哪個編碼是這樣的。。UTF-16be也應該是兩個漢字輸出6個啊
  • 1 回答
  • 0 關注
  • 1222 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號