Print Even-Odd Number

fun main() {
    println("Enter a Integer Number")//1
    val number = readLine()?.toInt()!!//2
    if(number%2==0)//3
    {
        println("Entered Number is Even=$number")//4
    }
    else
    {
        println("Entered Number is Odd=$number")//5
    }
}

1 Instruct the user to Enter a Integer value
2 Take value from command line and  convert it into Int and assign to number variable
3 Check Entered Number is Even or Odd using if statement
4 If statement true then on command line Entered Number is Even=20
5 If statement false then on command line Entered Number is Odd=5

Output:-
Enter a Number
 10
 Entered Number is Even

Enter a Number
 15
 Entered Number is Odd

Leave a Reply

Your email address will not be published. Required fields are marked *