عرض مشاركة واحدة
منتديات طلاب وطالبات جامعة الملك عبد العزيز منتديات طلاب وطالبات جامعة الملك عبد العزيز
قديم 25-12-2011, 10:20 PM   #392

Prince soma

Super Hussam

الصورة الرمزية Prince soma

 
تاريخ التسجيل: Sep 2011
التخصص: IT
نوع الدراسة: إنتظام
المستوى: الرابع
الجنس: ذكر
المشاركات: 266
افتراضي رد: Cpcs 202 شروحات وحلول وواجبات الجافا

المشاركة الأصلية كتبت بواسطة فوضـى مشاهدة المشاركة
مشكور اخوي ع المساعدة وما قصرت

كود PHP:
package javaapplication95 

import java.util.scanner;

public class 
javaapplication95 {

public static 
void main(string[] args) {

scanner in = new scanner(system.in);
system.out.print("enter an int value, the program exits if 

the input is 0:  "
);
int n in.nextint();

int positives  0,  negatives=,  count 0;
double sum=ave=0;
for (; ;) {
  
sum+=n;
  
count++;
  
  
if (
== 0)
break;

if (
0) {

positives ++;
}
else{
    
negatives++;
}
avesum/count;

system.out.print("enter an int value, the program exits if 

the input is 0:"
);
in.nextint();
}
system.out.println("the number of positives " +  positives 

);

system.out.print("the number of negatives   " negatives );

system.out.println (" \n the total is " sum );
 
system.out.println (" the average is " ave );


}


في الاخراج :

كود PHP:
enter an int valuethe program exits if the input is 0:
1 2 -1 3 0 
the number of positives is 3
the number of negatives is 1
the total is 5
the average is 1.25 

القيم : 1 2 -1 3 0 وين يكون مكانها في الكود

وحاولت انفذ البرنامج لكن في خطأ . اتمنى ما اكون تعبتك .
الارقام 1 2 -1 3 هذا مثلا فقط يعني البرنامج الي اعطيتك هو يمديك تدخل اي عدد في راسك

الى ان تدخل 0 راح يوقف عملية ادخال الارقام و يظهر الاشياء المطلوبة

يعني اذا ادخلت ارقام غير الموجودة في السؤال

هذه عملية الاخراج
كود PHP:
Enter an int valuethe program exits if the input is 0:  5
Enter an int value
the program exits if the input is 0:4
Enter an int value
the program exits if the input is 0:8
Enter an int value
the program exits if the input is 0:9
Enter an int value
the program exits if the input is 0:-4
Enter an int value
the program exits if the input is 0:-8
Enter an int value
the program exits if the input is 0:-1
Enter an int value
the program exits if the input is 0:3
Enter an int value
the program exits if the input is 0:0
The number of positives 5
The number of negatives   3 
 The total is 16.0
 The average is 2.0 
و هذا الناتج طلع صحيح

و ممكن توضح اش الخطأ الي يظهر لك

 


التعديل الأخير تم بواسطة Prince soma ; 25-12-2011 الساعة 10:26 PM.
Prince soma غير متواجد حالياً   رد مع اقتباس