Java将int转换为double

时间:2018-09-07 18:15:04

标签: java

我正在尝试使其在用户输入1,2和5时java输出类似2.66的内容。但是,它仅输出2.00。我该如何解决?

public static void main(String[] args) {

    Scanner in = new Scanner(System.in);

    System.out.print("Please input first integer: ");
    int a = in.nextInt();
    System.out.print("Please input second integer: ");
    int b = in.nextInt();
    System.out.print("Please input third integer: ");
    int c = in.nextInt();
    float calculateInput = (float)((a+b+c)/3);
    System.out.printf("The average of %s, %s, and %s is %.2f \n", a, b, c, calculateInput);

    double e = (double)(1+2+5)/3;
    System.out.print(calculateInput);
}

0 个答案:

没有答案