Write a Swift program to test if an array of integers contains a 4 or a 8

Topics

Introduction

I have used Swift for windows 1.9 for debugging purpose. But you can use any Swift programming language compiler as per your availability.

func checknumbers(_ a: [Int]) -> Bool {
    if a.contains(4) || a.contains(8)
    {
        return true
    } 
    else
    {
        return false
    }
}
print(checknumbers([2, 6, 7]))
print(checknumbers([4, 8]))
print(checknumbers([4, 8, 5]))

Result

Write a Swift program to test if an array of integers contains a 4 or a 8
Write a Swift program to test if an array of integers contains a 4 or a 8

 

Leave a Comment