因此,我很难弄清楚如何正确显示这些值。所有的数学都是正确的,但它只说明了整数。例如,当我输入数字 87、42 和 94 时,平均值应为 74.3 重复。然而它对我来说只有 74.0。最低分数的平均值也是如此。
Scanner keyboard = new Scanner(System.in);
int a;
int b;
int c;
double grade;
double avg;
double avg2 = 0;
System.out.print("Enter score number 1: ");
a = keyboard.nextInt();
System.out.print("Enter score number 2: ");
b = keyboard.nextInt();
System.out.print("Enter score number 3: ");
c = keyboard.nextInt();
avg = ((a + b + c) / 3);
System.out.println("The average is: " + avg);
if (a < b && a < c)
{
System.out.println("The lowest score was: " + a);
System.out.println("The average without the lowest score is: " + ((b + c) / 2));
avg2 = ((b + c) / 2);
}
if (b < a && b < c)
{
System.out.println("The lowest score was: " + b);
System.out.println("The average without the lowest score is: " + ((a + c) / 2));
avg2 = ((a + c) / 2);
}
if (c < a && c < b)
{
System.out.println("The lowest score was: " + c);
System.out.println("The average without the lowest score is: " + ((a + b) /2));
avg2 = ((a + b) / 2);
}