Dart int remainder()
Syntax & Examples


int.remainder() method

The `remainder` method in Dart's `int` class returns the remainder of the truncating division of this number by another number.


Syntax of int.remainder()

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.

Parameters

ParameterOptional/RequiredDescription
otherrequiredThe divisor for the division operation.

Return Type

int.remainder() returns value of type num.



✐ Examples

1 Remainder of integer division

In this example,

  1. We create an integer variable dividend with the value 10 and another variable divisor with the value 3.
  2. We use the remainder() method to find the remainder of dividend divided by divisor.
  3. We then print the result to standard output.

Dart Program

void main() {
  int dividend = 10;
  int divisor = 3;
  int remainder = dividend.remainder(divisor);
  print('Remainder of $dividend divided by $divisor: $remainder');
}

Output

Remainder of 10 divided by 3: 1

2 Remainder of integer division

In this example,

  1. We create an integer variable num with the value 42 and another variable divisor with the value 7.
  2. We use the remainder() method to find the remainder of num divided by divisor.
  3. We then print the result to standard output.

Dart Program

void main() {
  int num = 42;
  int divisor = 7;
  int remainder = num.remainder(divisor);
  print('Remainder of $num divided by $divisor: $remainder');
}

Output

Remainder of 42 divided by 7: 0

3 Remainder of integer division

In this example,

  1. We create an integer variable num with the value 25 and another variable divisor with the value 6.
  2. We use the remainder() method to find the remainder of num divided by divisor.
  3. We then print the result to standard output.

Dart Program

void main() {
  int num = 25;
  int divisor = 6;
  int remainder = num.remainder(divisor);
  print('Remainder of $num divided by $divisor: $remainder');
}

Output

Remainder of 25 divided by 6: 1

Summary

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.