当我以两倍的方式运行此代码时,会出现错误。整数可以正常工作,可以更改

时间:2018-12-12 02:07:19

标签: java math int double

import java.util.*;

public class Ford {
    public static void main(String[] args) {
        System.out.println("Input for t for A(t)=1500(1/2)^t/14");
        Scanner sc = new Scanner(System.in);
        double t = sc.nextInt();
        double a = 1500;
        double b = 0.5;
        double c = 2;
        double d = 14;
        double e = t / 2;
        double f = 14 / 2;
        double g = e / f;
        double h = c * g;
        double i = a / d;
        double j = c / d;
        double k = a / (15 / 7);
        double m = java.lang.Math.pow(c, g);
        double n = java.lang.Math.ceil(a / m);
        System.out.println("The total answer is " + n + " rounded to the nearest" + " tenth gram after " + t + " hours");
        System.out.println("The exponent * 2 is " + m);
        System.out.println(g);
    }
}

1 个答案:

答案 0 :(得分:1)

double t = sc.nextInt();

您的错误在此行中,您正尝试将一个int保存为双重使用,而不是

double t = sc.nextDouble();