Java.lang.StrictMath 类

java.lang.StrictMath.floorMod() 方法返回参数的下限模数。两个参数的下取模与两个参数的模相同。在特殊情况下,它返回以下内容:

  • 如果第二个参数为零,则此方法抛出 ArithmeticException。

语法

public static int floorMod(int x, int y)

参数

x 指定被除数。
y 指定除数。

返回值

返回下限模数参数。

异常

如果除数 y 为零,则抛出 ArithmeticException

示例:

在下面的示例中,floorMod() 方法返回两个参数的下限模数(余数)。

import java.lang.*;

public class MyClass {
 public static void main(String[] args) {
  System.out.println(StrictMath.floorMod(11, 4));   
  System.out.println(StrictMath.floorMod(10, 7));
  System.out.println(StrictMath.floorMod(3, -1));     
 }
}

上述代码的输出将是:

3
3
0