Division
You can divide any two double
s using the /
operator.
void main() {
double x = 8;
// y will be 4.0
double y = x / 2;
// z will be 1.3333333333333333
double z = y / 3;
System.out.println(x);
System.out.println(y);
System.out.println(z);
}
Unlike with integer division, floating point division will include the remainder in the result.1
1
With the caveat that the result is now potentially inaccurate.