InstagramTwitterSnapChat


 
وصف

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


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

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

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

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

moon alharbi moon alharbi غير متواجد حالياً

3>

 
تاريخ التسجيل: 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;
}
}
رد مع اقتباس

 

منتديات طلاب وطالبات جامعة الملك عبد العزيز منتديات طلاب وطالبات جامعة الملك عبد العزيز
قديم 24-02-2012, 04:28 PM   #2

deathpain

devkemo

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

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

المشاركة الأصلية كتبت بواسطة moon alharbi مشاهدة المشاركة
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;
}
}
السؤال بسيط جداً ،، حله كالتالي على حسب الكود:
1- نسوي كول للميثود إلي تحسب الأفرج داخل المين ميثود ونرسلها رقم من إدخال المستخدم باستخدام السكانر ونطبعها :
كود PHP:
Scanner input = new Scanner (System.in);
int x=input.nextInt();
System.out.println(average(x)); 
2- نسوي كول لنفس الميثود بس بدون ما نضع رقم داخل الباراميتر حق الكول ونطبع الناتج:
كود PHP:
System.out.println(average()); 
3- نسوي لووب داخل البرنامج تخلي المستخدم يدخل على الأكثر 20 رقم موجب داخل مصفوفة وإذا أدخل رقم سالب يخرج من اللوب ولا يسجل الرقم السالب ،،
كود PHP:
int[] array = new int [20];
for (
int i=0;i<array.length;i++){
array[
i]=input.nextInt();
if (array[
i]<0){
array[
i]=0;
break;} 
وهذا المطلوب منك بكل بساطة في البرنامج :)

4- نرسل الأراي للميثود حقت الأفرج ونطبع الناتج:
كود PHP:
System.out.println(average(array); 
بالتوفيق أختي ،،

أخوكي عبدالكريم

 

توقيع deathpain  

 



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

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

 

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

منتديات طلاب وطالبات جامعة الملك عبد العزيز منتديات طلاب وطالبات جامعة الملك عبد العزيز
قديم 24-02-2012, 08:58 PM   #3

حنو123

اللهم لك الحمد

الصورة الرمزية حنو123

 
تاريخ التسجيل: Feb 2010
كلية: كلية الحاسبات وتقنية المعلومات
التخصص: cs
نوع الدراسة: متخرج - انتظام
المستوى: متخرج
البلد: جــــدة
الجنس: أنثى
المشاركات: 1,091
افتراضي رد: }{ تعالو نفهم بعض الsheet }{....برمجة 2

المشاركة الأصلية كتبت بواسطة deathpain مشاهدة المشاركة
السؤال بسيط جداً ،، حله كالتالي على حسب الكود:
1- نسوي كول للميثود إلي تحسب الأفرج داخل المين ميثود ونرسلها رقم من إدخال المستخدم باستخدام السكانر ونطبعها :
كود PHP:
Scanner input = new Scanner (System.in);
int x=input.nextInt();
System.out.println(average(x)); 
2- نسوي كول لنفس الميثود بس بدون ما نضع رقم داخل الباراميتر حق الكول ونطبع الناتج:
كود PHP:
System.out.println(average()); 
3- نسوي لووب داخل البرنامج تخلي المستخدم يدخل على الأكثر 20 رقم موجب داخل مصفوفة وإذا أدخل رقم سالب يخرج من اللوب ولا يسجل الرقم السالب ،،
كود PHP:
int[] array = new int [20];
for (
int i=0;i<array.length;i++){
array[
i]=input.nextInt();
if (array[
i]<0){
array[
i]=0;
break;} 
وهذا المطلوب منك بكل بساطة في البرنامج :)



4- نرسل الأراي للميثود حقت الأفرج ونطبع الناتج:
كود PHP:
System.out.println(average(array); 
بالتوفيق أختي ،،

أخوكي عبدالكريم
مشكور اخوي عبد الكريم لكن هنا لمن يحسب الaverage راح يقسم على 20 حتى مثلا لو دخلت 3 ارقام موجبة فقط والناتج حيكون خطا

 

توقيع حنو123  

 


 

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

إضافة رد


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

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

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

 


الساعة الآن 06:30 PM


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