当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。