27-10-2014, 09:35 AM
|
#5
|
أصلاً أنا أحب الحاسب عادي
تاريخ التسجيل: Jul 2011
كلية: كلية الحاسبات وتقنية المعلومات
التخصص: ما احبه
نوع الدراسة: إنتظام
المستوى: متخرج
البلد: اوربا
الجنس: ذكر
المشاركات: 1,385
|
رد: سؤال بالبرمجه1
هذا الحل معقد شوي لاني حاولت اخلي البرنامج مايسوي crash
بس تقدري تحلينه باي طريقة ثانية ، ابسط من كذا
المهم تعرفين تستخدمين loop واللي داخله ، لانها هي معادلة الحل
كود PHP:
int integer ; // this is the Integer input
// this line to insert the integer from user as a STRING !
String mark = JOptionPane.showInputDialog("Enter an Integer");
// if user insert NOTHING , then this massege will be displyed
if(mark.isEmpty())
JOptionPane.showConfirmDialog(null,"No Input !" );
// else , means if user input an Integer
// So,
else{
// we have a STRING so we should convert it !
// this line will convert the String to Integer
integer = Integer.parseInt(mark);
// declaring a new Integer calling it "result"
// To save the result in it
int result=0;
// This is called - while loop
/* which means : while the Integer that we had, bigger than ZERO ,
the loop will repeat all the lines inside it until the Integer becomes ZERO ! **/
while(integer > 0)
{
// So, this two lines will be rebeated until Integer variable becomes ZERO
// First line : takes the integer%10 and save it in the Result variable
// second Line : will devide the Integer by 10 >>> and it will becomes smaller and smaller until becomes 0
result += integer%10;
integer = integer/10;
}
// this line to show the result to the user
JOptionPane.showConfirmDialog(null,"Grade = " + result);
انسخي والصقي في الـ main وشغليه
والشرح موجود في نفس الكود في التعليقات على كل سطر ، هناك شرح لكل سطر ووظيفته
|
|
سبحان الله وبحمده ، سبحان الله العظيم
|
|
|
|