Kotlin program to check whether a number is EVEN or ODD

Kotlin | Check EVEN or ODD: Here, we are going to learn how to check whether a given number is EVEN or ODD in Kotlin programming language? Submitted by IncludeHelp, on April 22, 2020

Problem statement

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"

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

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.