
مشكور اخوي ع المساعدة وما قصرت
كود 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=0 , count = 0;
double sum=0 , ave=0;
for (; ;) {
sum+=n;
count++;
if (n == 0)
break;
if (n > 0) {
positives ++;
}
else{
negatives++;
}
ave= sum/count;
system.out.print("enter an int value, the program exits if
the input is 0:");
n = 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 value, the 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 value, the 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
و هذا الناتج طلع صحيح
و ممكن توضح اش الخطأ الي يظهر لك