Programming Basics SQL HTML CSS JavaScript Python C++ Java JavaFX Swing Problem Solving English English Conversations Computer Fundamentals Learn Typing

الخوارزمياتتعريف دوال جديدة - المثال الأول

المثال التالي يعلمك طريقة بناء دالة مهمتها فقط عرض شيء للمستخدم.
الآن سنكتب دالة بسيطة إسمها DisplayMyInfo() تطبع لنا فقط بعض المعلومات عندما نقوم باستدعائها.


نتيجة التشغيل

كود الجافا

public class Methods {
public static void DisplayMyInfo()
{
System.out.print("My name is Mhamad Harmush \n");
System.out.print("I am from Lebanon \n");
System.out.print("I made harmash.com when I was 20 years old \n");
}
public static void main (String[] args)
{
DisplayMyInfo();
}
}
public class Methods { public static void DisplayMyInfo() { System.out.print("My name is Mhamad Harmush \n"); System.out.print("I am from Lebanon \n"); System.out.print("I made harmash.com when I was 20 years old \n"); } public static void main (String[] args) { DisplayMyInfo(); } }

شرح الكود


public static void DisplayMyInfo()
{
System.out.print("My name is Mhamad Harmush \n");
System.out.print("I am from Lebanon \n");
System.out.print("I made harmash.com when I was 20 years old \n");
}
public static void DisplayMyInfo() { System.out.print("My name is Mhamad Harmush \n"); System.out.print("I am from Lebanon \n"); System.out.print("I made harmash.com when I was 20 years old \n"); }
  • هنا قمنا بتعريف دالة إسمها DisplayMyInfo() تحتوي على 3 أوامر طباعة.


public static void main (String[] args)
{
DisplayMyInfo();
}
public static void main (String[] args) { DisplayMyInfo(); }
  • هنا قمنا بإستدعاء الدالة DisplayMyInfo() حتى يتم تنفيذ جميع أوامر الطباعة الموضوعة بداخلها.

شرح عملية الإستدعاء بتفصيل

نرجو منك الإنتقال لدورة البرمجة للمبتدئين الجديدة التي أنشأنها كبديل أفضل لهذه الدورة ففي تلك الدورة قمنا بتبسيط الشرح أكثر و جعلناك قادر على تجربة الكود بشكل مباشر في موقعنا.


دورة تعلم البرمجة للمبتدئين >