Java Long remainderUnsigned() Method

Java remainderUnsigned() method belongs to the Long 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.


public static long remainderUnsigned(long dividend, long divisor)


The parameters passed will be long dividend which will be divided and long 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 division process takes place with a positive and a negative value and the remainder obtained is an unsigned value.

import java.lang.Long;

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

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

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 );
      long Dividend = sc.nextLong();
      long Divisor = sc.nextLong();
      long result = Long.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 87 9
Remainder is: 6
Enter the Dividend and Divisor 333 -11
Remainder is: 333
Enter the Dividend and Divisor 0x556 90
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.