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

[تنبيه - عنوان غير مناسب : ]أرجو المساعدة من فضلك

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

أرجو شرح الجزء الملون من هذا البرنامج

// program to accept the full name of person and display the first and the last name.

Import java.util.*;

Public class Name

{

Public static void main (String [] args)

{

Scanner stdin=new Scanner (System .in);

System.out.print ("Enter your full name");

String s =stdin.nextline ();

Int n =s.IndexOf (" ", 0);

String f=s.substring (0, n);

int m=LastIndexOf (" ",s.length()-1);

String l=s.substring (m+1);

System.out.println (f+" "+l);

}

}

#2
 

[color= #003399;]String s [color= #339933;]=stdin.[color= #006633;]nextline [color= #009900;]([color= #009900;])[color= #339933;];

Int n [color= #339933;]=s.[color= #006633;]IndexOf [color= #009900;]([color= #0000ff;]" ", [color= #cc66cc;]0[color= #009900;])[color= #339933;];

[color= #003399;]String f[color= #339933;]=s.[color= #006633;]substring [color= #009900;]([color= #cc66cc;]0, n[color= #009900;])[color= #339933;];

[color= #000066; font-weight: bold;]int m[color= #339933;]=LastIndexOf [color= #009900;]([color= #0000ff;]" ",s.[color= #006633;]length[color= #009900;]([color= #009900;])[color= #cc66cc;]-1[color= #009900;])[color= #339933;];

[color= #003399;]String l[color= #339933;]=s.[color= #006633;]substring [color= #009900;](m[color= #cc66cc;]+1[color= #009900;])[color= #339933;];

الكلاس String يقدم دوال جيده للتعامل مع الString Operation ،

الداله IndexOf تخرج لك موقع الحرف المرسل ... الداله لها أشكال أخرى Overlaoding ،

 

[color= #000066; font-weight: bold;]int indexOf[color= #009900;]([color= #000066; font-weight: bold;]int ch[color= #009900;])

[color= #000066; font-weight: bold;]int indexOf[color= #009900;]([color= #003399;]String str[color= #009900;]) 

[color= #000066; font-weight: bold;]int indexOf[color= #009900;]([color= #000066; font-weight: bold;]int ch, [color= #000066; font-weight: bold;]int startIndex[color= #009900;]) 

[color= #000066; font-weight: bold;]int indexOf[color= #009900;]([color= #003399;]String str, [color= #000066; font-weight: bold;]int startIndex[color= #009900;])

الأولى تخرج موقع الحرف المرسل ،

الثانيه تخرج موقع الٍSubstring المرسل .

الثالثه تخرج لك موقع الحرف المرسل بدأ من الIndex الفلاني

الأخيره تخرج لك موقع الSubString بدأ من الموقع Index الفلاني .

وبنفس الشكل هناك الداله lastIndexOf وهي تخرج لك موقع الحرف لكن بدأ من النهايه ، ولهذه الداله أيضا أشكال Overloading Version :

 

[color= #000066; font-weight: bold;]int lastIndexOf[color= #009900;]([color= #000066; font-weight: bold;]int ch[color= #009900;])

[color= #000066; font-weight: bold;]int lastIndexOf[color= #009900;]([color= #003399;]String str[color= #009900;])

[color= #000066; font-weight: bold;]int lastIndexOf[color= #009900;]([color= #000066; font-weight: bold;]int ch, [color= #000066; font-weight: bold;]int startIndex[color= #009900;]) 

[color= #000066; font-weight: bold;]int lastIndexOf[color= #009900;]([color= #003399;]String str, [color= #000066; font-weight: bold;]int startIndex[color= #009900;])

نفس وظيفه الدواله السابقه ، لكن تبدأ من النهايه ،،،

بالنسبه للداله substring ، فهناك شكلين منها :

 

[color= #003399;]String substring [color= #009900;]([color= #000066; font-weight: bold;]int beginIndex[color= #009900;])[color= #339933;];

[color= #003399;]String substring [color= #009900;]([color= #000066; font-weight: bold;]int begin , [color= #000066; font-weight: bold;]int end[color= #009900;])[color= #339933;];

الأولى ترجع لك String جديد بدأ من الموقع الفلاني ،

الثانيه ترجع لك String جديد بدأ من الموقع الفلاني الى الموقع الفلاني ..

الداله length ترجع لك طول الString (عدد الحروف) ..

أما السطر الأول لديك :

String s =stdin.nextline ();

فهذه الداله nextLine تستخدم لقرائه سطر تالي من الـ Stream ، والStream لديك في حالتك هو الكيبورد ، لأنك حددته في السطر الذي قبله :

Scanner stdin=new Scanner (System .in);

للمزيد ، راجع هنا :

Java String Class

Class String in Documentation

بالتوفيق ،

http://informatic-ar.com منصة تعليمية عربية في علوم الحاسب والبرمجة

https://moalfat.com  للكتب الالكترونية والكورسات التعليمية

Everything we see now is just an engineering solution based on old science

#3

أشكرك أخي على جهدك وعلى الشرح الرائع ......

جزاك الله خيرا

#4

الأخ الكريم/الأخت الكريمة

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

مرحباً بكم في منتدى الفريق العربي للبرمجة

نود تنبيهك أن العنوان غير مناسب.

الرجاء اختيار عنوان مناسب أكثر في مواضيعك القادمة، وهذا بمثابة إشعار للأهمية.

وفي حال التكرار سيتعرض موضوعك للإغلاق والحذف!!!

قواعد المشاركة

/index.php?showtopic=29343

شاكرين لكم حُسن تعاونكم

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

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

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

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

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

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