+ 1
How does this work
I’m doing operations in java on basic concepts it told me x= 15 y= 4 as int variables then divided x/y and asked for the result which was somehow three pls explain
2 odpowiedzi
+ 2
It is integer dividing - output has to be an integer. So 15 / 4 = 3, and remainder from division is 2 -> 3 * 4 + 2 = 15. You can calculate that remainder with modulo (15 % 4 = 2).
+ 2
because you use int type variables, these are integers
int x = 15; int y = 4;
so 15/4 = 3
if you want to get more precision, use floating point numbers like float, double
double x = 15.0; double y = 4.0
so 15.0 / 4.0 = 3.75