Kotlin Program to find even and odd elements in an array
In this program, You will learn how to find even and odd elements in an array in Kotlin.
Array List are: 6 7 8 9 10
Odd list: 7 9
Even list: 6 8 10
Example: How to find even and odd elements in an array in Kotlin.
import java.util.Scanner
fun main(args: Array<String>) {
val arr = IntArray(5)
val sc = Scanner(System.`in`)
print("Enter 5 numbers:")
for (i in 0 until arr.size) {
arr[i] = sc.nextInt()
}
print("Even list are:")
for (n in arr) {
if (n % 2 == 0) {
print("$n ")
}
}
print("\nOdd list are:")
for (n in arr) {
if (n % 2 != 0) {
print("$n ")
}
}
}
Output:
Enter 5 numbers:2 3 4 5 6
Even list are:2 4 6
Odd list are:3 5