import java.util.Scanner;
public class javaj {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a = 0, b = 0;
double average, total = 0;
System.out
.println("Enter an int value,the program exits if the input is 0");
int n = input.nextInt();
while (n != 0) {
if (n > 0)
++a;
else
++b;
total += n;
n = input.nextInt();
}
average = total / (a + b);
System.out.println("The number of positives is " + a);
System.out.println("The number of negatives is " + b);
System.out.println("The total is " + total);
System.out.println("The average is " + average);
}
}
java课后题
最新推荐文章于 2024-04-25 20:43:17 发布