The `remainder` method in Dart's `int` class returns the remainder of the truncating division of this number by another number.
The syntax of int.remainder() method is:
num remainder(num other)
This remainder() method of int returns the remainder of the truncating division of this by other.
Parameter | Optional/Required | Description |
---|---|---|
other | required | The divisor for the division operation. |
int.remainder() returns value of type num
.
In this example,
dividend
with the value 10 and another variable divisor
with the value 3.remainder()
method to find the remainder of dividend
divided by divisor
.void main() {
int dividend = 10;
int divisor = 3;
int remainder = dividend.remainder(divisor);
print('Remainder of $dividend divided by $divisor: $remainder');
}
Remainder of 10 divided by 3: 1
In this example,
num
with the value 42 and another variable divisor
with the value 7.remainder()
method to find the remainder of num
divided by divisor
.void main() {
int num = 42;
int divisor = 7;
int remainder = num.remainder(divisor);
print('Remainder of $num divided by $divisor: $remainder');
}
Remainder of 42 divided by 7: 0
In this example,
num
with the value 25 and another variable divisor
with the value 6.remainder()
method to find the remainder of num
divided by divisor
.void main() {
int num = 25;
int divisor = 6;
int remainder = num.remainder(divisor);
print('Remainder of $num divided by $divisor: $remainder');
}
Remainder of 25 divided by 6: 1
In this Dart tutorial, we learned about remainder() method of int: the syntax and few working examples with output and detailed explanation for each example.