السلام عليكم ورحمة الله وبركاتة
كيفكم اخواني الاعضاء المبرمجين
أسعد الله مسائكم بالحب و المسرات
عندي اليوم برنامج ابي اكتب له 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;
}
}