السلام عليكم ورحمة الله وبركاته ..
لدي هنا مشكله اتمنى ان اجد حلها ..
لدي برنامج يقوم بالقراءه من ملف حيث يقوم بحساب عدد تكرار كل كلمه ومن ثم فرزها تنازليا والكلمات التي لها نفس العدد يتم فرزها على حسب الابجديه
طبعا هنا تم استخدام الهاش تيبل hashtable والذي لا اعرف عنه سوى القليل ,, المشكله في ان الكود يوجد به خطأ في النهايه حاولت تصحيح فتظهر لي مشكله اخرى
سأضع الكود هنا واتمنى المساعده
public class VocabList {
public static void main(String[] args) {
// create a hashtable
Hashtable<String, Integer> myHashtable = new Hashtable<String, Integer>();
// open a file
EasyReader file = new EasyReader("twinkle.txt");
// word counts
int totalNumberOfWords = 0;
// process line by line
while (!file.eof()) {
// read a string
String s = file.readString();
// remove leading/trailing white spaces & place a space in the end
s = s.trim() + ' ';
// find the length of the string
int l = s.length();
// repeat until all spaces are processed
while (l>0) {
// find the position of the first space
int i = s.indexOf(' ');
// identify the leading word and the rest of the string
String w = s.substring(0, i);
s = s.substring(i+1, l);
// process words
if (w.length()>0) {
// count the number of words processed
totalNumberOfWords++;
// find the current count
Integer n = (Integer)ht.get(w);
// create a new entry for a new word
if (n==null) {
myHashtable.put(w, new Integer(1));
}
// increase the count for a existing word
else {
n = (Integer)ht.remove(w);
myHashtable.put(w, new Integer(n+1));
}
}
// find the length of the string
l = s.length();
}
}
// display all words and the their counts
for (Enumeration<String> e = myHashtable.keys(); e.hasMoreElements(); ) {
String w = e.nextElement();
Integer n = (Integer)myHashtable.get(w);
System.out.println(w + " (" + n + ")");
}
// display statistics
System.out.println();
System.out.println("total number of words in \"news.txt\": " +
totalNumberOfWords);
System.out.println("vocabulary size: " + myHashtable.size());
String[] NumSortedArray = new String[myHashtable.size()];
for(int i = 0; i < myHashtable.size(); i++)
{
NumSortedArray;
}
}
}