Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now