Reference Materials
Certification Courses
Created with over a decade of experience and thousands of feedback.
Python online compiler
JavaScript online compiler
SQL online compiler
Java online compiler
HTML online compiler
C online compiler
C++ online compiler
C# online compiler
PHP online compiler
Swift online compiler
Kotlin online compiler
TypeScript online compiler
Go online compiler
Rust online compiler
Scala online compiler
Dart online compiler
R online compiler
Ruby online compiler
Swift Double isMultiple()
In this tutorial, we will learn about the Swift Double isMultiple() method with the help of examples.
The isMultiple() method checks if one number is multiple of another or not.
Example
// check is 9 is multiple of 3 or not
var result = 9.isMultiple(of: 3)
print(result)
// Output: true
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- ifnumis multiple ofotherNumberfalse- ifnumis not a multiple ofotherNumber
Example 1: Swift Double isMultiple()
// check if 4 is multiple of 2 or not
var result1 = 4.isMultiple(of: 2)
print(result1)
// check if 2 is multiple of 4 or not
var result2 = 2.isMultiple(of: 4)
print(result2)
// check if 210 is multiple of 10 or not
var result3 = 210.isMultiple(of: 10)
print(result3)
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
// check if 48 is multiple of 2 or not
if 48.isMultiple(of: 2) {
print("Even Number")
}
else {
print("Odd number")
}
Output
Even Number
Here, since 48 is multiple of 2, the code inside the if block is executed.
Did you find this article helpful?