rem

operator fun rem(other: Integer): Integer

Returns the remainder of dividing this integer by the other one, or throws an ArithmeticException if the other integer is zero.


Calling from Kotlin

Here's an example of calling this function from Kotlin code:

// Given
val x: Integer = Integer.from(42)
val y: Integer = Integer.from(5)
// When
val result: Integer = x % y
// Then
val expected: Integer = Integer.from(2)
check(result == expected)

Calling from Java

Here's an example of calling this function from Java code:

// Given
final Integer x = Integer.from(42);
final Integer y = Integer.from(5);
// When
final Integer result = x.rem(y);
// Then
final Integer expected = Integer.from(2);
final boolean check = result.equals(expected);
if (!check) throw new IllegalStateException("Check failed.");

See the remOrNull function for returning null instead of throwing an exception in case of invalid other integer.