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);
}
}
Asked
Active
Viewed 44 times
-2

SamHoque
- 2,978
- 2
- 13
- 43

user9851152
- 1
- 1
-
Okay now, What's the error? because the code works fine for me! – SamHoque Dec 12 '18 at 02:09
-
I figured it out i was running it with 30.5 and getting an error. I changed the scanner to double and it works now. – user9851152 Dec 12 '18 at 02:23
-
@SamzSakerz *What's the error?* - key point isn't it. – Scary Wombat Dec 12 '18 at 02:27
-
@ScaryWombat I will post an answer – SamHoque Dec 12 '18 at 02:28
1 Answers
1
double t = sc.nextInt();
Your error is in this line, You are trying to save an int to a double use this instead
double t = sc.nextDouble();

SamHoque
- 2,978
- 2
- 13
- 43
-
-
@ScaryWombat Pretty sure the question wasn't about that since the title says `double it gives an error. An integer works fine` so this would be the obvious answer. But Yeah I am not a math guy you can address it in your own answer – SamHoque Dec 12 '18 at 02:38
-
`14 / 2` returns a warning aswell in my IDE, so that isn't right either for `double f = 14 / 2;` – SamHoque Dec 12 '18 at 02:38
-
No, the problem is that `(15 / 7)` does integer division and thus gives a result of `2`, not `2.14....` but as you say, that is not his question. – Scary Wombat Dec 12 '18 at 02:40
-
-
-
@user9851152 No, My answer already addresses the problem. You can't "SET" a scanner to an object, You can retrive an object from the scanner which may be an int or double. – SamHoque Dec 12 '18 at 03:30