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

Method

بدأه غريب الداار في 2 أبريل 2011 · 2 رد · 672 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

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

كيفكم اخواني الاعضاء المبرمجين

أسعد الله مسائكم بالحب و المسرات

عندي اليوم برنامج ابي اكتب له method

هذا الاول

Write a methods

Method name: countOccurrenceOfCharacter

Parameters: String word1, char d

Return: int

Logic: Method should search word1 for the letter in d, and returns how many time it located that letter

in the string.

وهذا التاني

Method name: countOccurrenceOfMultiplesOf5

Parameters: int num1, int num2

Return: int

Logic: Method should count how many number between num1 and num2, included, are multiples of 5.

Method Name: filter

Parameters:int num

Return:String

Logic: Using Switch statement,if num is 1, 2, 3 returns “school day”, if 4, or 7

returns “Off Day”. Otherwise, returns “Nightmare”

وهل طريقة كتابة البرنامج مثل هذة الطريقة

Fix the logical Errors
//The method below should compare two strings,
//returns “same” if two Strings are identical.
//If they differ, determines the position of
//the first letter at which the two strings differs,
//and returns that position
public String compareStrings(String a,String b){
int  pos =0;
if (a.equals(b)){
return "same";
}else{
 while (b.charAt(pos)!=a.charAt(pos));
 {
pos++;
}
return "They differ at position:" + pos;
}
}

تم تعديل هذه المشاركة بواسطة .S.T.A.L.K.E.R في 2 أبريل 2011 في 14:52

#2
اقتباس

Fix the logical Errors //The method below should compare two strings, //returns “same” if two Strings are identical. //If they differ, determines the position of //the first letter at which the two strings differs, //and returns that position public String compareStrings(String a,String b){ int pos =0; if (a.equals(b)){ return "same"; }else{ while (b.charAt(pos)!=a.charAt(pos)); { pos++; } return "They differ at position:" + pos; } }

هذا الحل للسؤال الاول؟

اذا كان كذلك فهو خطأ

على كل لنفترض انك اجتهدت وحاولت فى حل السؤال الاول ونساعدك فى الاجابة

	public int countOccurrenceOfCharacter(String word1, char d) {

    	int found = 0;

    	for (char ch : word1.toCharArray()) {
        	if (ch == d) {
            	found++;
        	}
    	}

    	return found;
	}

بالتوفيق


﴿وَمَا كَانَ اللَّهُ لِيُعَذِّبَهُمْ وَأَنْتَ فِيهِمْ ۚ وَمَا كَانَ اللَّهُ مُعَذِّبَهُمْ وَهُمْ يَسْتَغْفِرُونَ﴾

الأنفال ۳۳                                  
 

#3

شكرا جزيلا

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