×

Java Math floorMod() Method

The floorMod() method of Math class returns the floor modulus of the specified arguments. It firstly divides the dividend and divisor and then returns an integer that is equal to the remainder.

Syntax:

  1. public static int floorMod (int x, int y)
  2. public static long floorMod (long x, int y)
  3. public static long floorMod (long x, long y)

Parameters:

The parameter ‘x’ and ‘y’ represents the dividend and the divisor.

Return Value:

The floorMod () method returns the floor modulus.

Example 1:

public class JavaMathFloorModExample1 {
    public static void main(String[] args) {
        int x = 2125;
        int y= 10;
        // divides x an y and returns the remainder .
        System.out.println("Remainder : "+Math.floorMod(x, y));
    }
}

Output:

Remainder : 5

Example 2:

public class JavaMathFloorModExample2 {
    public static void main(String[] args) {
        int x = 2125;
        long y= -10;
        // divides x an y and returns the remainder
        System.out.println("Remainder : "+Math.floorMod(x, y));
    }
}

Output:

Remainder : -5

Example 3:

public class JavaMathFloorModExample3 {
    public static void main(String[] args) {
        long x = -2125;
        long y= 0;
        //it returns an Airthmetic Exception, if the Second argument is zero
        System.out.println(Math.floorMod(x, y));
    }
}

Output:

Exception in thread "main" java.lang.ArithmeticException: / by zero
          at java.lang.Math.floorDiv(Math.java:1086)
            at java.lang.Math.floorMod(Math.java:1166)
            at com.javaTpoint.JavaMathFloorModExample3.main
(JavaMathFloorModExample3.java:8)

Example 4:

public class JavaMathFloorModExample4 {
    public static void main(String[] args) {
        long x = 2125;
        long y= -1;
        //it y is 1 or -1 then it will return 0
        System.out.println(Math.floorMod(x, y));
    }
}

Output:

 0

Related Topics

Types of Events in Java

One of Java's key ideas is the principle of an event. Events in Java are activities that result in a change in the state or behavior of an object. The...

4 minutes read.

Functional Interfaces in Java

Java has forever remained an Object-Oriented Programming language. By object-oriented programming language, we can declare that everything present in the Java programming language rotates throughout the Objects, except for some...

11 minutes read.

Compile time vs Runtime in java

Introduction: This article will discuss compile time vs. runtime in java. Compile time and runtime are two programming terms utilized in software improvement. Compile time is when the source code is...

3 minutes read.

Fork Join in Java

Multithreaded processors are being introduced in new computer systems today. The operation is faster due to multicore CPUs. Therefore, it becomes essential for a programmer to leverage multithreaded processors effectively...

4 minutes read.

Java instance variable

An instance in object-oriented programming (OOP) is a particular implementation of any object. Each realized version of an item, which might vary in several ways, is an instance. Instantiation is...

3 minutes read.

Java String Matches vs Contains

String Matches in Java The matches() function and its variations are used to determine whether or not a provided text matches a regular expression. The functioning as well as output of...

3 minutes read.

How to check Date is Greater in Java?

In this article, you will be acknowledged about how to check if the given date is greater than the other date or not. We are simply comparing the dates and...

7 minutes read.

Java this keyword

This Keyword in Java This keyword can be used in many different ways in Java. This is a reference variable in Java that points to the active object. In Java, the...

8 minutes read.

StringBuffer in Java

StringBuffer in Java Similar to StringBuilder, the Java StringBuffer class is also used to create modifiable or mutable strings. The StringBuilder class is synchronized, i.e., thread-safe. Java StringBuffer ConstructorThe StringBuffer class has...

7 minutes read.

Java Applications

The growth in technology is increasing rapidly, so some languages are used for developing them. Java is one such famous programming language which is having numerous applications. The Java Programming...

4 minutes read.

Java Binary to Hexadecimal

Converting between types in programming is an important task. Moving from one kind to another kind conversion is occasionally necessary. We have discussed numerous conversion types in the section on...

3 minutes read.

Java Viva Questions and Answers

Question: Explain Java programming language. Answer: It is a high-level programming language. This programming language is based on the principles of object-oriented programming. Large-scale applications can be developed by using this...

16 minutes read.

How to stop execution after a certain time in Java

We will learn how to stop a long-running execution after a set amount of time in this post. We will take a look at a few alternative approaches to this...

6 minutes read.

Tetranacci Number in Java

This article mainly describes tetranacci number identification and the Java Program for Tetranacci numbers. Tetranacci number Tetranacci numbers and Fibonacci numbers are related. The key contrast is that a Tetranacci number depends...

3 minutes read.

How to get ASCII value of char in Java

Introduction: On this application, you will learn how to find and show the ASCII value of char in Java. That is done with the use of type-casting and also everyday...

4 minutes read.

Java Serialization

JAVA SERIALIZATION Serialization is a process by which objects can be represented as a sequence of bytes. These bytes have information about object's data, object's type and datatypes of members in...

3 minutes read.

Types of Statements in Java

In natural languages, statements and sentences are roughly equivalent. In general, statements are similar to valid English sentences. We will talk about a statement in Java and the different kinds...

11 minutes read.

Java Math decrementExact() Method

The decrementExact() method of Math class returns the argument which is decremented by one, throwing an exception is the result overflows an int or long. Syntax: public static int decrementExact (int a) Parameters: The...

1 minute read.

Alice and Bob Problem Java

Alice and Bob were two friends who liked to play games. Both together found a game, which has the description below. The game begins with an integer num, used to create...

2 minutes read.

Java Open File

Java Desktop class give an open() strategy to open a filr. It has a place with a java.awt package. Work area execution is stage subordinate, so it is important to...

5 minutes read.