Swift Double isMultiple()

The isMultiple() method checks if one number is multiple of another or not.

Example


isMultiple() Syntax

The syntax of the isMultiple() method is:

num.isMultiple(of: otherNumber)

Here, num is a number.


isMultiple() Parameters

The isMultiple() method takes one parameter

  • otherNumber - the value to test

isMultiple() Return Values

The isMultiple() method returns boolean value

  • true - if num is multiple of otherNumber
  • false - if num is not a multiple of otherNumber

Example 1: Swift Double isMultiple()

Output

true
false
true

Here, since 4 is a multiple of 2, the isMultiple() method returns true. However, 2 is not a multiple of 4, the method returns false.

Lastly, since 210 is multiple of 10, the method returns true.


Example 2: Check Odd or Even

Output

 
Even Number

Here, since 48 is multiple of 2, the code inside the if block is executed.