Java – How to do floor division?

You can do

double val = 5 / 2;
int answer = Math.floor(val);

OR

int answer = Math.floorDiv(5, 2);

If you were to call System.out.println(answer); the output would be

2

Leave a Comment