どうすれば平均化できますか?. GPA
の平均、学生の合計、および の合計を求めるとしますGPA
。例:
入力: 4 4 4 4
出力: 総生徒数:4
総GPA: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);
}
}