×

Java Integer remainder Unsigned() method

The remainderUnsigned() method of Java Integer class returns the unsigned remainder by dividing the first and second argument. Syntax public static int remainderUnsigned(int dividend, int divisor)  Parameters The ‘dividend’ and ‘divisor’ represents the value to be divided and the value doing the dividing.  Return Value This method returns an unsigned remainder by dividing the dividend with divisor. Example 1
public class JavaIntegerRemainderUnsignedExample1 {
    public static void main(String[] args) {
      Integer dividend=120;
      Integer divisor=7;
      int quotient= Integer.divideUnsigned(dividend,divisor);
        System.out.println(dividend+"/"+divisor+" = "+quotient);
      int remainder= Integer.remainderUnsigned(dividend,divisor);
        System.out.println("Remainder = "+remainder);
    }
}
Output
12/7 = 1
Remainder = 5
Example 2
public class JavaIntegerRemainderUnsignedExample2 {
    public static void main(String[] args) {
        Integer dividend=Integer.MAX_VALUE;
        Integer divisor=Integer.MIN_VALUE;
        // returns the MAX_VALUE if MAX_VALUE and MIN_VALUE are divided
        int quotient= Integer.divideUnsigned(dividend,divisor);
        System.out.println(dividend+"/"+divisor+" = "+quotient);
        int remainder= Integer.remainderUnsigned(dividend,divisor);
        System.out.println("Remainder = "+remainder);
    }
}
Output
2147483647/-2147483648 = 0
Remainder = 2147483647
Example 3
public class JavaIntegerRemainderUnsignedExample3 {
    public static void main(String[] args) {
        Integer dividend=Integer.MAX_VALUE;
        Integer divisor=0;
        // Gives an exception if divisor is 0
        int quotient= Integer.divideUnsigned(dividend,divisor);
        System.out.println(dividend+"/"+divisor+" = "+quotient);
        int remainder= Integer.remainderUnsigned(dividend,divisor);
        System.out.println("Remainder = "+remainder);
    }
}
Output
Exception in thread "main" java.lang.ArithmeticException: / by zero

              at java.lang.Integer.divideUnsigned(Integer.java:1294)

              at com.TutorialAndExample.JavaIntegerRemainderUnsignedExample3.main(JavaIntegerRemainderUnsignedExample3.java:8)

Related Topics

Java Switch string

A multi-way branch statement is the switch statement. It offers a simple method for allocating execution to various code sections according to the expression's value. Primitive data types, including bytes,...

3 minutes read.

Java Boolean logicalXor() Method

The logicalXor() method of Java Boolean class returns the result of implementing logical XOR operation on the specified Boolean operands. Syntax: public static boolean logicalXor (boolean a, boolean b) Parameters: The parameters ‘a’ and...

2 minutes read.

Read JSON file in Java

 To know about reading a JSON file in Java first we must know about the JSON file. JSON: JSON is “JavaScript Object Notation”. The JSON is the simple format for storing and...

3 minutes read.

How to install Java in Windows 10

To make programs that can run on our systems, we need to install the programming language related software in our systems. Different programming language requires a different type of software aka...

6 minutes read.

Exception Handling Program in Java

Exception Handling Program in Java Exception means something that is abnormal. In Java, an exception is treated as a problem that disrupts the normal flow of the program. An exception leads...

7 minutes read.

Getting the Day from the Date in Java?

To extract the day's name from the date, we will write Java application. When dealing the date and time in Java, the following classes are used. Class for Calendars: This class is...

6 minutes 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.

Lombok Java

What is Lombok java? A well-liked and widely-used Java framework that is used to reduce or eliminate boilerplate code is called Project Lombok. Both time and effort are saved. We may...

7 minutes read.

Java List Implementations

ArrayList and LinkedList are the two implementations of List that are for general-purpose. You'll probably utilise an array list the majority of the time because it's quick and provides constant-time...

3 minutes read.

Centered Square Numbers in Java

In this tutorial, we will understand how to check the number is a centered square number. It is one of the prevalent interview questions of IT companies. Firstly, we will...

3 minutes read.

Converting Long to Date in Java

What Long and Date are in Java and how are they implemented in the Java programming language are the topics of this article. Additionally, we'll go into great detail on...

4 minutes read.

Java CountDownLatch

Another crucial classes for concurrent execution is CountDownLatch. It is a synchronisation tool that enables one or more threads to await until a series of tasks started by another thread...

4 minutes read.

Java Get Time in UTC

UTC is the abbreviation for Universal Time Coordinated. Before the beginning of UTC, it is mentioned as the Greenwich Mean Time (GMT) but Now it is mentioned as the universal...

4 minutes read.

Program to Reverse a Number in Java

In order to reverse a number, the digit in the first place must be swapped with the digit in the final position, the second digit with the second-to-last digit, and...

3 minutes read.

How to Create Singleton Class in Java

In this tutorial, we will discuss the singleton class and how to create it. Introduction Java is a purely object-oriented programming language. It consists of classes and objects. But Singleton is one...

4 minutes read.

Traverse through HashMap in Java

In this tutorial, we will discuss traversing through HashMap in Java Introduction: HashMap<Key, Value> is a part of the java collection implemented from the java 1.2 version. HashMap is written as HashMap<K,...

4 minutes read.

Java Get File Size

There are three ways to get the file size in Java. Using Java InputOutput Using NewInputOutput Library Files.size() Method FileChannel.size() Method Using Apache Commons InputOutput Using Java InputOutput: The Java IO package offers the classes that deal...

5 minutes read.

Sorting a String in Java

Sorting a String in Java Sorting is a process of arranging available data objects in a meaningful format that is ascending or descending order. Sorting a string or array of String...

4 minutes read.

Sliding Window Problem in Java

A sliding window is used in computer science and data science to process large datasets. It involves breaking the dataset into smaller chunks or windows and then processing it in...

6 minutes read.

Java Session

Session indicates interval of time. A session is a simple  time interval in which servers and client interacts. To maintain the state of the client or user we use technologies...

5 minutes read.