Signup/Sign In
LAST UPDATED: OCTOBER 16, 2020

Java Integer remainderUnsigned() Method

Java remainderUnsigned() method belongs to the Integer class. This method is used to return the remainder (unsigned) obtained by dividing the first argument with the second argument. The result i.e the remainder is always taken as an unsigned value.

Syntax:

public static int remainderUnsigned(int dividend, int divisor) 

Parameters:

The parameters passed will be int dividend which will be divided and int divisor which will be doing the division process.

Returns:

the unsigned remainder when the first argument(i.e dividend) is divided by the second argument(i.e divisor).

Example 1:

Here, the normal division process takes place as all the integers are signed.

import java.lang.Integer;

public class StudyTonight 
{  
    public static void main(String[] args) 
    {  
        int a = 100;  
        int b = 5;
        int c = 3;        
        System.out.println("Remainder of\t" + a+ "/" +b+ "\t is \t" +Integer.remainderUnsigned(a, b));  
        System.out.println("Remainder of\t" + a+ "/" +c+ "\t is \t" +Integer.remainderUnsigned(a, c));  
    }  
}  


Remainder of 100/5 is 0
Remainder of 100/3 is 1

Example 2:

Here is a user-defined example where anyone using this code can put a value of his choice and get the equivalent output.

import java.util.Scanner;  
public class StudyTonight
{  
    public static void main(String[] args) 
    {  
        try
        {
           System.out.print("Enter the Dividend and Divisor ");               
           Scanner sc = new Scanner(System.in);                      
           int Dividend = sc.nextInt();                              
           int Divisor = sc.nextInt();           
           int result = Integer.remainderUnsigned(Dividend, Divisor); //return the unsigned remainder       
           System.out.println("Remainder is: "+result);                   
        }
        catch(Exception e)
        {
          System.out.println("Invalid Input!!");
        } 
    }  
}  


Enter the Dividend and Divisor 78 9
Remainder is: 6
*****************************************
Enter the Dividend and Divisor -56 9
Remainder is: 2
******************************************
Enter the Dividend and Divisor 100 0
Invalid Input!!

Live Example:

Here, you can test the live code example. You can execute the example for different values, even can edit and write your examples to test the Java code.



About the author:
A Computer Science and Engineering Graduate(2016-2020) from JSSATE Noida. JAVA is Love. Sincerely Followed Sachin Tendulkar as a child, M S Dhoni as a teenager, and Virat Kohli as an adult.