- 1
why is "result" equals 0.0 in eclipse? (code in the message)
class MyClass{ public static void main(String[]args) { int x=1; int y=3; double result=x/y; System.out.println(result); } }
1 Antwort
+ 2
Because even if the var where its saved is doubled, you are dividing int. You can solve that Making the 1 and 3 doubles, or using Promotion:
double result= (double) x/y;