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

سؤال عن Method باستخدام String

مغلق
بدأه سيف المعاني في 27 أكتوبر 2007 · 4 رد · 648 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السؤال كالتالي:

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.

الرجاء المساعدة ولكم جزيل الشكر

#3

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

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 {


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

تم تعديل هذه المشاركة بواسطة عيسى عايد العنزي في 27 أكتوبر 2007 في 10:50 — السبب: اضافة كود تاق

#4

أهلاً نواف !

شكراً لمشاركتك واتمنى ان اراك دائما معنا

#5

اولا اشكر الاخ عيسى على التكرم بالرد

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

هذا الموضوع مغلق.

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