New Tutorials:   NUMPY    TKINTER    KOTLIN    JAVASCRIPT    SASS/SCSS    PL/SQL    Matplotlib    C++ Programs
See the Tutorial List

Java Integer divideUnsigned() Method

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

Syntax:

public static int divideUnsigned(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 quotient 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("Quotient of\t" + a+ "/" +b+ "\t is \t" +Integer.divideUnsigned(a, b));  
        System.out.println("Quotient of\t" + a+ "/" +c+ "\t is \t" +Integer.divideUnsigned(a, c));  
       }  
}  


Quotient of 100/5 is 20
Quotient of 100/3 is 33

Example 2:

Here, integer 100 is divided with numbers from -5 to +5 to clear the concept of the method. Output will be zero for signed integers and respective quotient for the unsigned integers.

import java.lang.Integer;
public class StudyTonight 
{  
    public static void main(String[] args) 
     {  
         int a = 100;  
         try
           {
             for(int i=-5;i<=5;i++)
               {
                 if(i==0)
                  {
                     System.out.println("Division with zero not possible");
                  }
                 else
                   {
                     System.out.println("Quotient of\t" + a+ "/" +i+ "\t is \t" +Integer.divideUnsigned(a, i));  
                   } 
          
                }
            }
         catch(Exception e)
            {
          
            }
        
        
       }        
}  


Quotient of 100/-5 is 0
Quotient of 100/-4 is 0
Quotient of 100/-3 is 0
Quotient of 100/-2 is 0
Quotient of 100/-1 is 0
Division with zero not possible
Quotient of 100/1 is 100
Quotient of 100/2 is 50
Quotient of 100/3 is 33
Quotient of 100/4 is 25
Quotient of 100/5 is 20

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.