×

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

Monsoon Umbrella Problem in Java

The Monsoon Umbrella problem is a classic Java programming problem used to test the skills of a programmer. The problem involves writing a program to determine the number of umbrellas...

3 minutes read.

Java Swings

Swing is a Java Foundation Class library and an extension to the Abstract Window Toolkit (AWT) (JFC).As compared to AWT, Swing has significantly better functionality, new components, increased component features,...

9 minutes read.

Java Set to List

In this article, you will be acknowledged about how the process of conversion from Set or HashSet to LinkedList happens and what are the possible ways involved in conversion process. First...

4 minutes read.

Java Image

For all other classes used for representing graphical images, Java's Image class serves as an abstract superclass. For images in Java, a specific form of object known as a BufferedImage...

4 minutes read.

URLConnection Class

What is the URL? URL stands for Uniform Resource Locator, is used to specify addresses on the World Wide Web. A URL relates to the identification of any resource connected to the web. URL syntax: Protocol://hostname/other_information(files...

6 minutes read.

Java Math log1p() Method

The log1p() method of Math class returns the natural logarithmic sum for the specified double argument and 1. Its value is much closer to result of ln(1 + x). Syntax: public static...

2 minutes read.

Java Plot

Java Plot is a phrase in Java that is mostly used for plotting coordinates on a cartesian plane. Plotting graphs in Java is accomplished through the use of various core...

3 minutes read.

Pangram Program in Java

If a string comprises all alphabet letters from A to Z or from a to z without regard to case, it is referred to as a pangram. Some examples of pangram...

3 minutes read.

Java FileNotFoundException

FileNotFoundException is another exception class accessible in the java.io bundle. The exemption happens when we attempt to get to that document which isn't accessible in the framework. It is a checked...

5 minutes read.

Annotations in Java

Annotations in Java Java Annotations are metadata about the source code. They do not have any direct effect on the execution of the java program. Annotations in Java were introduced in...

4 minutes read.

Java gc()

Garbage collection Java language provides different ways to perform the task of memory management. In Java, objects are declared and assigned references. Once lifeof an object is completed it is dereferenced...

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 Architecture

Java architecture is a combination of three parts they are JVM, JRE and JDK. These components will help in the functioning of the java programs. The process of code interpretation...

6 minutes read.

Java Math floorDiv() Method

The floorDiv () method of Math class returns the largest integer value that is less than or equal to the algebraic quotient. It firstly divides the dividend and divisor and...

2 minutes read.

Java String Reader

StreamReaderClass: This class is present in the java.io package. It is a character stream in which string act as a source.This method provides to read characters from a string. Character Stream: This class...

3 minutes read.

What is the ambiguity problem in Java?

The ambiguity problem in Java occurs when a method or constructor is overloaded with two or more methods with the same name but different parameters. This can confuse when multiple...

6 minutes read.

Java callable example

What is callable in Java? Callable is an interface that is present in Java. There are two methods for constructing threads: one is to inherit the Thread class, while the other...

3 minutes read.

Singleton class in Java

What is Singleton class in Java? Singleton means it is one. That means we can create only one instance or object of a class. For example, let us have a class...

3 minutes read.

Java concurrency interview questions

During technical interviews, one of the most challenging and sophisticated subjects is concurrency in Java. This page offers responses to some of the related interview questions you might come across. 1....

11 minutes read.

Class definition in Java

The class definition in Java Java is an object-oriented programming language. We essentially know that programming languages based on object-oriented paradigms have classes and objects in their concepts as main, which...

6 minutes read.