我如何平均?我想找到GPA
学生总数和学生总数的平均值GPA
。例子:
输入:4 4 4 4
输出: 学生总数:4
总平均绩点:16
平均GPA: 4
import java.util.Scanner;
public class practice {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int count = 0;
double GPA = 0, total = 0, average;
System.out.println("Enter GPA");
while (GPA >= 0) {
GPA = keyboard.nextDouble();
total = total + GPA;
count++;
}
average = total / count;
System.out.println("Total students: " + count);
System.out.println("Total GPA " + total);
System.out.println("Average GPA " + average);
}
}