當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java Integer divideUnsigned()用法及代碼示例

divideUnsigned() 是 Java Integer 類的一個方法,它返回第一個參數除以第二個參數的無符號商,其中每個參數和結果都被解釋為一個無符號值。

用法:

以下是 divideUnsigned() 方法的聲明:

public static int divideUnsigned(int divident, int divisor)

參數:

數據類型 參數 描述 必需/可選
int dividend 它是一個將被分割的 int 值。 Required
int divisor 將進行除法過程的值。 Required

返回值:

divideUnsigned() 方法返回第一個參數除以第二個參數的無符號商。

異常:

NA

兼容版本:

Java 1.8 及以上

例子1

public class IntegerDivideUnsignedExample1 {
    public static void main(String[] args) {
        int a = 55;
        int b = 5;		 
        System.out.println("Output quotient:"+Integer.divideUnsigned(a, b));
        }
}

輸出:

Output quotient:11

例子2

public class IntegerDivideUnsignedExample2 {
    public static void main(String[] args) {
        System.out.println("Output quotient:"+Integer.divideUnsigned(61, 3));
        }
}

輸出:

Output quotient:20

例子3

import java.util.Scanner;
public class IntegerDivideUnsignedExample3 {
        public static void main(String[] args) {
            //Ask the input from user
            System.out.print("Enter the Divident Value:");				
            Scanner sc = new Scanner(System.in);					
            int Divident = sc.nextInt();							
            System.out.print("Enter the Divisor value:");
            int Divisor = sc.nextInt();			
            //Divide the two user input (unsigned value)
            int result = Integer.divideUnsigned(Divident, Divisor);		
            //Print the output			
            System.out.println("Quotient:"+result);					
            sc.close();
              }
}

輸出:

Enter the Divident Value:566
Enter the Divisor value:15
Quotient:37

示例 4

import java.util.Scanner;
public class IntegerDivideUnsignedExample4 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
            System.out.println("Divide the user inputs (unsigned integer):");	
            Integer val1 = sc.nextInt();
            Integer val2 = sc.nextInt();
            Integer val3 = sc.nextInt();
            sc.close();
            System.out.println("The Results are:");
            System.out.println(Integer.divideUnsigned(val1,val2));
            System.out.println(Integer.divideUnsigned(val1,val3));
        }
}

輸出:

Divide the user inputs (unsigned integer):
155
5
-5
The Results are:
31
0






相關用法


注:本文由純淨天空篩選整理自 Java Integer divideUnsigned() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。