الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مساعده في ايجاد عدد تكرار الكلمات

بدأه clasic في 17 نوفمبر 2008 · 3 رد · 851 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله وبركاته ..

لدي هنا مشكله اتمنى ان اجد حلها ..

لدي برنامج يقوم بالقراءه من ملف حيث يقوم بحساب عدد تكرار كل كلمه ومن ثم فرزها تنازليا والكلمات التي لها نفس العدد يتم فرزها على حسب الابجديه

طبعا هنا تم استخدام الهاش تيبل 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;
	}
}
	}
#2

وضح أكثر عن الخطأ

تحياتي

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

#3

السلام عليكــم ورحمـة الله وبركاتــه

أخي ما هو EasyReader ? أين يوجد هذا الكلاس ؟

وشكرا

مواقع أعجبتني :

دورة عربية في الـ J2ME

#4

يبدو أنها فئة من صنع كاتب الموضوع

تحياتي

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…