object Scala_Array {
def test(arr: Array[Int]): Boolean = {
arr.exists(x => x == 4 || x == 7)
}
def main(args: Array[String]): Unit = {
var nums1 = Array(2,4,5,7,9)
println("Orginal array:")
for ( x <- nums1) {
print(s"${x}, ")
}
println("\nIf 4 or 7 present in the said array? "+test(nums1))
var nums2 = Array(2,5,5,6,9)
println("Orginal array:")
for ( x <- nums2) {
print(s"${x}, ")
}
println("\nIf 4 or 7 present in the said array? "+test(nums2))
var nums3 = Array(2,5,7,6,9)
println("Orginal array:")
for ( x <- nums3) {
print(s"${x}, ")
}
println("\nIf 4 or 7 present in the said array? "+test(nums3))
}
}
Sample Output:
Console (F3)
Orginal array:
2, 4, 5, 7, 9,
If 4 or 7 present in the said array? true
Orginal array:
2, 5, 5, 6, 9,
If 4 or 7 present in the said array? false
Orginal array:
2, 5, 7, 6, 9,
If 4 or 7 present in the said array? true
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer