Kotlin Program to check the age of a user is eligible for voting or not
In this program, You will learn how to check the age of a user who is eligible for voting or not in Kotlin.
if (age >= 18) {
//statement
}
Example: How to check the age of a user is eligible for voting or not in Kotlin.
import java.util.Scanner
fun main(args: Array<String>) {
var age: Int
var sc = Scanner(System.`in`)
print("Enter age of a user:")
age = sc.nextInt()
if (age >= 18) {
println("User is valid for voting:$age")
} else {
println("User is not valid for voting:$age")
}
}
Output:
Enter age of a user:19
User is valid for voting:19