عرض مشاركة واحدة
منتديات طلاب وطالبات جامعة الملك عبد العزيز منتديات طلاب وطالبات جامعة الملك عبد العزيز
قديم 27-11-2011, 12:36 AM   #6

deathpain

devkemo

الصورة الرمزية deathpain

 
تاريخ التسجيل: Dec 2010
كلية: كلية الحاسبات وتقنية المعلومات
التخصص: Computer Science
نوع الدراسة: إنتظام
المستوى: الثامن
البلد: جــــدة
الجنس: ذكر
المشاركات: 770
افتراضي رد: ساعدوني في واجب لاب البرمجة

المشاركة الأصلية كتبت بواسطة هــــايدي مشاهدة المشاركة
هذا هو السؤال ياليييييييييييييييييت تساعدوني
The following code is the solution of the "Lab Exercise 3-Largest Number” in sheet 5.

Scanner input = new Scanner( System.in );

int largest; // largest number
int number; // user input
int counter; // number of values entered

/* write code to get the first integer and store it in variable largest */
System.out.println( "Enter the number 1:" );
number = input.nextInt();
largest=number;
/* write code to initialize the number of integers entered */
counter=2;
/* write code to loop until 10 numbers are entered */
while(counter<=10)
{
/* write code to prompt the user to enter a number and read that number */
System.out.println( "Enter the number "+counter+":" );
number = input.nextInt();
/* write code to test whether the number entered is greater than the largest if so, replace the value of largest with the entered number */
if(number>largest)
largest=number;
/* write code to increment the number of integers entered */
counter++;
}
System.out.printf( "Largest number is %d\n", largest );


Q1:Modify the program to find the largest value of the x values entered.
read x from user. 0.5
أولاً أعتذر عن التأخر في الإجابة لأنني كنت خارج المنزل،

حل السؤال:
كود PHP:
Scanner input = new ScannerSystem.in );  
    
int largest,number,counter=1,maximum=0;
    
System.out.println("Enter the number of values you want to input: ");
    
maximum input.nextInt();
    
System.out.println("Enter the number "+counter+":");
    
number input.nextInt();
    
largest number;
    while(
counter<=maximum){
    
System.out.println("Enter the number "+counter+":");
    
number input.nextInt();
    if(
number>largest)
    
largest=number;
    
counter++;}
    
System.out.printf("Largest number is %d\n"largest ); 
أولاً تعرفين متغير جديد يحدد كم عدد القيم التي يود ادخالها المستخدم، نفرض maximum
نخلي المستخدم هو الي يدخل قيمة maximum باستخدام سكانر،
نعدل الشرط حق while بدل ما يكون counter<=10 نشيل الـ10 ونحط بدالها maximum حتى يقوم كل مرة بإدخال أعداد حتى يصل لحد maximum ومن ثم يطبع أكبر قيمة ،،
أتمنى إن يكون الحل واضح وشكراً

 

توقيع deathpain  

 



في حال وجود أي استفسار أو سؤال حول الجافا CPCS202 الرجاء كتابة استفسارك مباشرة في موضوعي هنا:

تطبيق - معدلي الجامعي - التطبيق الأسهل لحساب المعدل الجامعي
http://skaau.com/vb/showthread.php?t=745520

 

deathpain غير متواجد حالياً   رد مع اقتباس