Tech Study

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

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

 

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

Java Final keyword

Introduction : java final keyword The final keyword present in Java programming language is generally used for restricting the user. …

Read more

C++ Memory Management: new and delete

C++ Memory Management We know that arrays store contiguous and the same type of memory blocks, so memory is allocated …

Read more