Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

Java Data Type Exercises: Compute the floor division and the floor modulus of the given dividend and divisor

Java Data Type: Exercise-13 with Solution

Write a Java program to compute the floor division and the floor modulus of the given dividend and divisor.

Sample Solution:

Java Code:

public class Main {
    public static void main(String[] args) {
        int x = -2365;
        int y = 125;
        System.out.println();
        System.out.println("Floor division using '/' operator: " + (x / y));
        System.out.println("Floor division using floorDiv() method is: " + Math.floorDiv(x, y));
        System.out.println();
        System.out.println("Floor modulus using '%' operator: " + (x % y));
        System.out.println("Floor modulus using floorMod() method is: " + Math.floorMod(x, y));
    }
}

Sample Output:

Floor division using '/' operator: -18
Floor division using floorDiv() method is: -19

Floor modulus using '%' operator: -115
Floor modulus using floorMod() method is: 10

Flowchart:

Flowchart: Java Data Type Exercises - Compute the floor division and the floor modulus of the given dividend and divisor

Java Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a Java program to compare two given signed and unsigned numbers.
Next: Write a Java program to extract the primitive type value from a given BigInteger value.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Java: Tips of the Day

How to sort an ArrayList?

Collections.sort(testList);
Collections.reverse(testList);

That will do what you want. Remember to import Collections though!

Ref: https://bit.ly/32urdSe