Java – How to do floor division?

We Are Going To Discuss About Java – How to do floor division?. So lets Start this Java Article.

Java – How to do floor division?

  1. Java – How to do floor division?

    You can easily use Math.floorDiv() method.
    For example:
    int a = 15, b = 2; System.out.println(Math.floorDiv(a, b)); // Expected output: 7

  2. How to do floor division

    You can easily use Math.floorDiv() method.
    For example:
    int a = 15, b = 2; System.out.println(Math.floorDiv(a, b)); // Expected output: 7

Solution 1

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

Original Author A J Of This Content

Solution 2

You can easily use Math.floorDiv() method.
For example:

int a = 15, b = 2; 
System.out.println(Math.floorDiv(a, b));
// Expected output: 7

Original Author Deniz Can Tufekci Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment