I was trying to solve a simple question for my homework as below.
// variable dm represents deciemeter and has been initialized earlier in //the code, e.g as
//int dm = 1;
// Correct the formula down below so it will pass all test cases
double meter = dm/10;
System.out.print( meter );
At first, I thought nothing was wrong and hit "check answer", which returned value 0, the expected value was 0.1. After some testing I concluded that the correct way was to declare meter as java double meter = (double) dm/10
But why is this the correct way? Is it because dm was declared as an int, so 0.1/10 is calculated by the computer, assuming that the answer should be an integer? If this is the case, why doesn't the computer already figure it out when I declared meter as a double?