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.
4 Answers
+ 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)