فيما يلي امثلة لاستخدام المتحولات variables في جافا
كود جمع متغيرين من نوع string:
كود جمع متغيرين من نوع رقم:
كود ادخال الاسم والكنية من الكيبورد وجمعهما وطباعة النتيجة:
كود ادخال رقمين من الكيبورد وجمعهما وطباعة نتيجة الجمع:
كود تعريف متغير من نوع boolean وطباعته:
برنامج لحساب مساحة ومحيط المربع:
write java program to calculate square area and perimeter, program should prompts user to enter side length, then calculate the area and perimeter based on it
برنامج لحساب مساحة ومحيط المستطيل:
write java program to calculate rectangle area and perimeter, program should prompts user to enter length and width, then calculate the area and perimeter based on it
variable VS constant in java
مقارنة بين المتغير والثابت في جافا:
برنامج يحسب مساحة دائرة:
اولويات العمليات الرياضية في جافا:
الاولوية بالترتيب كالتالي:
- الاس ^ power
- الزيادة بمقدار واحد ++ increment والنقصان بمقدار واحد -- decrement
- باقي القسمة Remainder %
- الضرب والقسمة * / multiplication and subtraction
- الاشارات الايجابية + والاشارات السلبية - unary plus and minus operators
- الجمع والطرح + - add and subtract
- المساواة = assignment
Casting in java
امثلة على قص انواع البيانات في لغة جافا
امثلة عن استخدام المتغيرات ( المتحولات variables ) في لغة البرمجة java
--------------------------------------------------------------------------------------------------------
برنامج يقوم بالتبديل بين قيمتي متحولين, باستخدام متحول وسيط مؤقت:
مثال الة حاسبة بسيطة, تقوم بتنفيذ العمليات الحسابية الاربعة على عددين مدخلين من الكيبورد:
برنامج يحسب مساحة الشكل المسدس(سداسي الاضلاع):
برنامج يحسب فوائد القروض باستخدام Java :
برنامج يحسب المسافة بين نقطتين:
برنامج يحسب طول المدرج بناءا على تسارع الطائرة:
مثال اخر :
برنامج طبي لحساب معادل ال BMI:
برنامج يطلب من المستخدم ادخال قيم 3 نقاط تشكل مثلث ومن ثم يحسب ويطبع مساحة المثلث:
مثال على استخدام المتغيرات وعمليات الادخال والطباعة:
(Science: calculating energy) Write a program that calculates the energy needed
to heat water from an initial temperature to a final temperature. Your program
should prompt the user to enter the amount of water in kilograms and the initial
and final temperatures of the water. The formula to compute the energy is
Q = M * (finalTemperature – initialTemperature) * 4184
where M is the weight of water in kilograms, temperatures are in degrees Celsius,
and energy Q is measured in joules.
(Physics: acceleration) Average acceleration is defined as the change of velocity
divided by the time taken to make the change, as shown in the following formula:
v1 - v0
a = ---------
t
Write a program that prompts the user to enter the starting velocity v0 in meters/
second, the ending velocity v1 in meters/second, and the time span t in seconds,
and displays the average acceleration.
(Current time) Listing 2.7, ShowCurrentTime.java, gives a program that displays
the current time in GMT. Revise the program so that it prompts the user to enter
the time zone offset to GMT and displays the time in the specified time zone.
(Find the number of years) Write a program that prompts the user to enter the
minutes (e.g., 1 billion), and displays the number of years and days for the minutes.
For simplicity, assume a year has 365 days. Here is a sample run:
(Sum the digits in an integer) Write a program that reads an integer between 0 and
1000 and adds all the digits in the integer. For example, if an integer is 932, the
sum of all its digits is 14.
Hint: Use the % operator to extract digits, and use the / operator to remove the
extracted digit. For instance, 932 = 2 and 932 / 10 = 93.
(Financial application: calculate tips) Write a program that reads the subtotal
and the gratuity rate, then computes the gratuity and total. For example, if the
user enters 10 for subtotal and 15% for gratuity rate, the program displays $1.5
as gratuity and $11.5 as total.
برنامج يطلب من المستخدم ادخال الاسم الاول والكنية ويطبع الاسم الكامل:
مثال برنامج يقوم بحساب مجموع قيم رتب الاحاد والعشرات والمئات للرقم:
طباعة جدول يوضح نتائج حساب القوة للعدد:
برنامج يقوم بحساب مساحة المثلث: