When dividing two 'int' variables and saving the result into a 'double' variable, anything to the right of the decimal point is just zero?
See the three examples below.
Thank you in advance, Mike
Example 1 public class MyClass {
public static void main(String[] args) {
int x, y, answer;
x = 70;
y = 30;
answer = x / y;
System.out.print(answer);
}
}
Output = 2 (I understand the result, all variables defined as 'int')
Example 2 public class MyClass {
public static void main(String[] args) {
int x, y;
double answer;
x = 70;
y = 30;
answer = x / y;
System.out.print(answer);
}
}
Output = 2.0 (I don't understand the result, the variable answer is 'double' and I expected 2.3333333333333335)
Example 3 public class MyClass {
public static void main(String[] args) {
double x, y, answer;
x = 70;
y = 30;
answer = x / y;
System.out.print(answer);
}
}
Output = 2.3333333333333335 (I understand the result, all variables defined as 'double')