kotlin 判斷數字
Given a number N, we have to check whether it is EVEN or ODD.
給定數字N ,我們必須檢查它是偶數還是奇數 。
Example:
例:
Input:
N = 13
Output:
"ODD"
Input:
N = 24
Output:
"EVEN"
程序在Kotlin檢查偶數或奇數 (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
翻譯自: https://www.includehelp.com/kotlin/check-whether-a-number-is-even-or-odd.aspx
kotlin 判斷數字