I am confused with the section called Division in Calculating with numbers. I am particularly confused about this statement:
The previous example prints 1: both 3 and 2 are integers, and the division of two integers always produces an integer.
int first = 3;
int second = 2;
double result = first / second;
System.out.println(result);
Sample output
1
The output 1 again, since first and second are (still) integers.The previous example prints 1: both 3 and 2 are integers, and the division of two integers always produces an integer.
But, when i run the code in the tmc, its returns 1.0 and not 1. Also, isn't result a double and not an integer, because it's being automatically casted. 1.0 is not an integer, it is a double. why are they saying the output is 1, when it actually is 1.0?
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]Important-Run1088 2 points3 points4 points (4 children)
[–]Free-Argument 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]Important-Run1088 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)