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.

26th May 2020, 12:17 AM
Zach Janzen
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.
26th May 2020, 12:25 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Thank you!
26th May 2020, 12:29 AM
Zach Janzen
0
You must cast to int int u =(int)( h.nextDouble()*food)
26th May 2020, 12:32 AM
Rahman Rezaie šŸ‡¦šŸ‡«
Rahman Rezaie šŸ‡¦šŸ‡« - avatar