因此,我很难找出如何使值正确出来。所有的数学都是正确的,但它只是表示整个数字。例如,当我输入数字87,42和94时,平均值应该重复74.3。但它只对我而言是74.0。最低分的平均值也一样。我将如何从java中的整数获得double值?
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);
}
您是否尝试在计算中用“3.0d”或“2.0d”而不是“3”或“2”进行划分? – JScoobyCed
@JScoobyCed你不需要'3.0'后面的'd'因为'3.0'已经是双倍的了 –