0
I need help with this error in java.
I need to help identify and solve this error. I’ll post the code that causes an error double food = 0.25; int u = h.nextDouble() * food; System.out.println(f); System.out.println(h.nextInt()); Based on the variable, you may be able to tell what I’m working on. 😂 Thank you if you’re able to help me with this.
3 Antworten
+ 2
You're attempting to implicitly cast a double to an int.
h.nextDouble() * food
results in a double type which is larger than type int. You need to either change the variable u to a double or explicitly cast the rvalue to an int.
+ 1
Thank you!
0
You must cast to int
int u =(int)( h.nextDouble()*food)