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


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


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

用法:

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

public static int remainderUnsigned(int divident, int divisor)

參數:

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

返回值:

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

異常:

NA

兼容版本:

Java 1.8 及以上

例子1

public class IntegerRemainderUnsignedExample1 {
	public static void main(String[] args) {
	   int a = 55;
	   int b = 16;		 
	   System.out.println("Output Remainder:"+Integer.remainderUnsigned(a, b));
	   }
}

輸出:

Output Remainder:7

例子2

public class IntegerRemainderUnsignedExample2 {
	public static void main(String[] args) {
		int Remainder =  Integer.remainderUnsigned(555,5);
		System.out.println("Remainder is:"+Remainder);		    
		Remainder =  Integer.remainderUnsigned(500,6);
		System.out.println("Remainder is:"+Remainder);
		}
}

輸出:

Remainder is:0
Remainder is:2

例子3

import java.util.Scanner;
public class IntegerRemainderUnsignedExample3 {
	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.remainderUnsigned(Divident, Divisor);		
		//Print the output			
		System.out.println("Remainder is:"+result);				
		sc.close();
		}
}

輸出:

Enter the Divident Value:324734
Enter the Divisor value:19
Remainder is:5

示例 4

import java.util.Scanner;
public class IntegerRemainderUnsignedExample4 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
            System.out.println("Enter the user inputs to find the remainder (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.remainderUnsigned(val1,val2));
            System.out.println(Integer.remainderUnsigned(val1,val3));
	     }
}

輸出:

Enter the user inputs to find the remainder (unsigned integer):
154
5
-5
The Results are:
4
154






相關用法


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