مشكور اخوي ع المساعدة وما قصرت
كود 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 وين يكون مكانها في الكود
وحاولت انفذ البرنامج لكن في خطأ . اتمنى ما اكون تعبتك .