شكرا الله يجزاك خير
بسس ,, ي ليت تحلوو مثاال لاني حااسه ما أستوعبتهاا تمااااام
For questions 10–12, assume the following class declaration
public class Value
{
public static void main( String args[] )
{
int x;
int xLimit;
/* assign values to x and xLimit here */
while ( x<= xLimit )
{
x++;
System.out.printf("The value of x is %d\n", x );
} // end while
System.out.printf("The final value of x is %d\n", x );
} // end main
}// end class Value
===================================
. What will be the output if the following code is placed at line 8 of the class?
x = 1;
xLimit = 5;
Your answer:
===================================
. What will be the output if the following code is placed at line 8 of the class?
x = 1;
xLimit = -2;
©
Your answer:
===================================
. What will be the output if the following code is placed at line 8 of the class?
x = 10;
xLimit = 5;
Your answer:
===================================
...
|
الأسئلة من هذا النوع بسيطة جداً ،، كلها مجرد طباعة للمخرجات ،، أنا فصلت الأسئلة عن بعضها بالخط الأحمر عشان تتوضح،
بالنسبة للسؤال الأول طلب منك تعريف المتغيرين x و xLimit وإعطاها قيم مبدئية،
نفرض x = 5 وxLimit = 10، هو استخدم printf عشان يطبع قيمة العدد العشري x مكان %d ،، واستخدم While عشان يطبع جميع قيم x حتى يصل لقيمة xLimit،
كود PHP:
int x=5;
int xLimit=10;
while ( x<= xLimit ){
x++;
System.out.printf("The value of x is %d\n", x );}
System.out.printf("The final value of x is %d\n", x );
لاحظي النواتج تطلع بهذا الشكل:
The value of x is 6
The value of x is 7
The value of x is 8
The value of x is 9
The value of x is 10
The value of x is 11
The final value of x is 11
--------------------------------------------------------------
السؤال الثاني يقولك ماهي النواتج الي راح تطلع لو حطيتي x=1 وxLimit=5 ،،
نفس طريقة السؤال الأول، النواتج:
The value of x is 2
The value of x is 3
The value of x is 4
The value of x is 5
The value of x is 6
The final value of x is 6
--------------------------------------------------------------
السؤال الثالث يقولك ماهي النواتج الي راح تطلع لو حطيتي x=1 وxLimit=2
النواتج:
The value of x is 2
The value of x is 3
The final value of x is 3
--------------------------------------------------------------
السؤال الرابع يقولك ماهي النواتج إلي راح تطلع لو حطيتي x=10 وxLimit=5 ،،
النواتج:
The final value of x is 10
ليش ما طبع الأعداد لين 10 ؟ الجواب: لأنه ما حقق الشرط داخل while وهو أن تكون قيمة x أقل من أو تساوي xLimit ،،
أتمنى أن اكون وفقت في الشرح ،، وبالتوفيق أختي