Division between integers in Java
I need to perform division between integers in Java, and the result should be a float.
Could I just use /
symbol for it? As in:
int integer1 = 1;
int integer2 = 2;
float quotient = integer1 / integer2; // Could I do this?
Solution 1:
Cast one of the integers to float to ensure a floating point division:
float result = integer1 / (float) integer2