Q:

Kotlin program to check whether a number is EVEN or ODD

belongs to collection: Kotlin Basic Programs

0

Given a number N, we have to check whether it is EVEN or ODD.

Example:

    Input:
    N = 13

    Output:
    "ODD"

    Input:
    N = 24

    Output:
    "EVEN"

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program to check EVEN or ODD in Kotlin

/* 	
    * Kotlin program to Input Integer 
    * Numbers and check Number is Even or ODD 
*/

package com.includehelp.basic

import java.util.*

// Main Method Entry Point of Program
fun main(args: Array<String>) {
    // InputStream to get Input
    val reader = Scanner(System.`in`)
    
    //Input Integer Value
    println("Enter Integer Value : ")
    var number = reader.nextInt();
    
    val str = if(number%2==0) "EVEN" else "ODD"
    
    println("Number is $str")
}

Output

RUN 1:
Enter Integer Value :
34
Number is EVEN
---
Run 2:
Enter Integer Value :
15
Number is ODD

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Kotlin Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Kotlin program to check whether given number is po... >>
<< Kotlin program to convert distance Miles to KM and...