InstagramTwitterSnapChat


 
وصف

العودة   منتديات سكاو > الكليات الجامعية > منتدى كلية الحاسبات وتقنية المعلومات > المنتدى العام لكلية الحاسبات وتقنية المعلومات
التسجيل مشاركات اليوم البحث
   
   


المنتدى العام لكلية الحاسبات وتقنية المعلومات قسم خاص بالمواد العامة و الطلاب غير المتخصصين بكلية الحاسبات وتقنية المعلومات

}{ تعالو نفهم بعض الsheet }{....برمجة 2

المنتدى العام لكلية الحاسبات وتقنية المعلومات

 
 
أدوات الموضوع إبحث في الموضوع انواع عرض الموضوع
منتديات طلاب وطالبات جامعة الملك عبد العزيز منتديات طلاب وطالبات جامعة الملك عبد العزيز
قديم 24-02-2012, 03:58 PM   #14

moon alharbi

3>

الصورة الرمزية moon alharbi

 
تاريخ التسجيل: Sep 2010
التخصص: IT
نوع الدراسة: إنتظام
المستوى: الخامس
الجنس: أنثى
المشاركات: 72
افتراضي رد: }{ تعالو نفهم بعض الsheet }{....برمجة 2

The file Parameters.java contains a program to test the variable length method average from Section 7.5 of the text. Note that average must be a static method since it is called from the static method main.

1. Compile and run the program. You must use the -source 1.5 option in your compile command.

2. Add a call to find the average of a single integer, say 13. Print the result of the call.

3. Add a call with an empty parameter list and print the result. Is the behavior what you expected?

4. Add an interactive part to the program. Ask the user to enter a sequence of at most 20 nonnegative integers. Your program should have a loop that reads the integers into an array and stops when a negative is entered (the negative number should not be stored). Invoke the average method to find the average of the integers in the array (send the array as the parameter). Does this work?

^ هذي الخطوة طفشتني ..نقرتين لعرض الصورة في صفحة مستقلة .. كمان كيف
send the array as the parameter؟

5. Add a method minimum that takes a variable number of integer parameters and returns the minimum of the parameters. Invoke your method on each of the parameter lists used for the average function.

وهنا كمان مافهمت كيف اسوي الميثود

كود:
//*
// Parameters.java
//
// Illustrates the concept of a variable parameter list.
//*
import java.util.Scanner;
public class Parameters
{
//-----------------------------------------------
// Calls the average and minimum methods with
// different numbers of parameters.
//-----------------------------------------------
public static void main(String[] args)
{
double mean1, mean2;
mean1 = average(42, 69, 37);
mean2 = average(35, 43, 93, 23, 40, 21, 75);
System.out.println ("mean1 = " + mean1);
System.out.println ("mean2 = " + mean2);
}
//----------------------------------------------
// Returns the average of its parameters.
//----------------------------------------------
public static double average (int ... list)
{
double result = 0.0;
if (list.length != 0)
{
int sum = 0;
for (int num: list)
sum += num;
result = (double)sum / list.length;
}
return result;
}
}

 

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

 


تعليمات المشاركة
لا تستطيع إضافة مواضيع جديدة
لا تستطيع الرد على المواضيع
لا تستطيع إرفاق ملفات
لا تستطيع تعديل مشاركاتك

BB code is متاحة
كود [IMG] متاحة
كود HTML معطلة

الانتقال السريع

 


الساعة الآن 02:40 AM


Powered by vBulletin® Version 3.8.9 Beta 3
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Ads Organizer 3.0.3 by Analytics - Distance Education

أن كل ما ينشر في المنتدى لا يمثل رأي الإدارة وانما يمثل رأي أصحابها

جميع الحقوق محفوظة لشبكة سكاو

2003-2025