المساعدة - البحث - قائمة الأعضاء - التقويم
نسخة كاملة: سؤال عن Method باستخدام String
برمجة - شبكات - كمبيوتر - منتديات الفريق العربي للبرمجة > منتديات لغات البرمجة العام > منتدى مبرمجي لغة جافا JAVA
سيف المعاني
السؤال كالتالي:

Write a method int matchSub(String s, String substring); that returns the first position where the substring is found in s. Note: use String methods. Write a main() to test this.

الرجاء المساعدة ولكم جزيل الشكر
Nawaf Alanazi
السلام عليكم ورحمة الله وبركاته



Write a method int matchSub(String s, String substring); that returns the first position where the substring is found in s. Note: use String methods. Write a main() to test this.

Soulution ( الحل ) :-
كود
public class TestingSub {[/size]

[size=3]
public static void main(String []args) {

String test = "WelcomeToJavaWorld";
String testSub = "Java";

int index = matchSub1(test,testSub);

System.out.println("The First Position where the substring \"Java\" where found: " + index);

}
public static int matchSub1(String s, String substring) {

String ss = s;
String sub = substring;

return ss.indexOf(sub);

}

}


ملاحظه: يجب ان يكون الكود في ملف اسمه TestingSub.java

Eisa Ayed
أهلاً نواف !
شكراً لمشاركتك واتمنى ان اراك دائما معنا
سيف المعاني
اولا اشكر الاخ عيسى على التكرم بالرد


ثانيا اشكرك اخي نواف جزيل الشكر على الحل الرائع وجزاك الله خيرا يا اخي

هذه "نسخة - خفيفة" من محتويات الرئيسية للإستعراض الكامل مع المزيد من الصور والخيارات الرجاء إضغط هنا.
Invision Power Board © 2001-2009 Invision Power Services, Inc.