第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

急求幫忙糾一下錯,詳細的講解一下這個程序,謝謝!

急求幫忙糾一下錯,詳細的講解一下這個程序,謝謝!

pstereo 2016-11-22 21:50:35
import?java.io.*;?//在測試時,這里有錯誤:無法解析java.util.Map$Entry.從必需的.class文件間接引用了它,怎么修改呢? import?java.util.ArrayList; import?java.util.Collections; import?java.util.HashMap; import?java.util.Iterator; import?java.util.List; import?java.util.Map; ?? import?javax.swing.JFrame; import?javax.swing.JTextArea; ?? public?class?T4?{ ?? ????@SuppressWarnings("unchecked") ????public?static?void?main(String[]?args)?throws?IOException?{ ?? ????????String?fileName?=?"Hello.txt"; ????????RandomAccessFile?file?=?new?RandomAccessFile(new?File(fileName),?"r"); ?????????? ????????String?content?=?null; ?????????? ????????Map<String,?Integer>?map?=?new?HashMap<String,?Integer>(); ?????????? ????????while((content?=?file.readLine())?!=?null){ ?????????????? ????????????String[]?ary?=?content.replaceAll("'|\\?|,|\\.|",?"").split("\\s+"); ?????????????? ????????????for(String?str?:?ary){ ????????????????if(map.containsKey(str.trim())){ ????????????????????map.put(str,?new?Integer(map.get(str).intValue()?+?1)); ????????????????}else{ ????????????????????map.put(str.trim(),?new?Integer(1)); ????????????????} ????????????} ????????} ?????????? ????????List?list?=?new?ArrayList(); ?????????/*下面for循環(huán)顯示錯誤:此行的多個標記-?Iterator?是原始類型。應(yīng)該將對通用類型?Iterator<E>?的引用參數(shù)化 ????????????????????????????????????????????????-類型?Map<String,Integer>?中的方法?entrySet()引用缺少的類型?Map$Entry*/? ????????for?(Iterator?iter?=?map.entrySet().iterator();?iter.hasNext();)?{?????????????????????????????????????????????????????????????????? ??????????Map.Entry<String,?Integer>?element?=?(Map.Entry<String,?Integer>)?iter.next(); ??????????list.add(new?WordFreq(element.getKey(),?element.getValue())); ????????} ????????/*下面一行顯示的錯誤是:無法解析類型?java.util.Comparator。從必需的?.class?文件間接引用了它 ????????????????????????????????-?Comparator?無法解析為類型 ????????????????????????????????-?類型?Collections?中的方法?sort(List<T>,?Comparator<??super?T>)引用缺少的類型? ?Comparator?*/ ????????Collections.sort(list,?new?Comparator<WordFreq>(){ ????????public?int?compare(WordFreq?o1,?WordFreq?o2)?{ ???????????return?o1.getCount()?<?o2.getCount()??1:?-1; ????????} ????????}); ?????????? ????????int?uniqueCount?=?0; ????????final?StringBuilder?sb?=?new?StringBuilder(); ????????final?String?NEW_LINE?=?"\r\n"; ?????????? ????????for(Object?obj:?list){ ????????????WordFreq?item?=?(WordFreq)?obj; ????????????uniqueCount?+=?(item.getCount()?==?1??1:?0); ????????????sb.append(item.toString());????????//這里顯示的錯誤是:無法解析類型?java.lang.CharSequence?從必需的?.class?文件間接引用了它 ????????????sb.append(NEW_LINE); ????????} ?????????? ????????JFrame?f?=?new?JFrame(); ????????JTextArea?result?=?new?JTextArea(); ?????????? ????????result.append("Total?"?+?list.size()?+?"?words?found?in?"?+?fileName); ????????result.append(NEW_LINE); ????????result.append("Total?"?+?uniqueCount?+?"?words?appear?only?once"); ????????result.append(NEW_LINE); ????????result.append(NEW_LINE); ????????result.append(sb.toString()); ?????????? ????????f.add(result); ????????f.setVisible(true); ????????f.pack(); ????????f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ?????????? ????} ?? } ?? class?WordFreq{ ????private?String?word; ????private?int?count; ?????? ????public?WordFreq(String?word,?int?count){ ????????this.word?=?word; ????????this.count?=?count; ????} ?? ????public?int?getCount()?{ ????????return?count; ????} ?????? ????public?String?toString(){ ????????return?word?+?"\t"?+?count; ????} ?????? }
查看完整描述

目前暫無任何回答

  • 0 回答
  • 0 關(guān)注
  • 2060 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號