kotlin 判断数字_Kotlin程序检查给定数字是正数,负数还是零
生活随笔
收集整理的這篇文章主要介紹了
kotlin 判断数字_Kotlin程序检查给定数字是正数,负数还是零
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
kotlin 判斷數字
A positive number is a number which is greater than 0, a negative number is a number which is less than 0, else the number is Zero.
正數是大于0的數字,負數是小于0的數字,否則為零。
Given a number num, we have to check whether it is positive, negative, or zero.
給定數字num ,我們必須檢查它是正數,負數還是零。
Example:
例:
Input:num = 12321Output:12321 is positive在Kotlin中檢查數字為正,負或零的程序 (Program to check number is positive, negative or zero in Kotlin)
/* Kotlin Program to Check a Integer Number is Positive or Negative or Zero if number > 0 = Positive Number else if number < 0 = Negative Number else Number is 0 (Zero) */package com.includehelp.basicimport java.util.*//Main Function, Entry Point of Program fun main(args: Array<String>) {// InputStream to get Inputval reader = Scanner(System.`in`)//Input Integer numberprint("Enter Integer Number : ")val num = reader.nextInt()// using if else println("Using if else...")if (num > 0)println("$num is a Positive Number")else if (num < 0)println("$num is a Negative Number")elseprintln("Entered Number is Zero")// using when statement (similar to switch case)println("Using when statement...") when{num> 0 -> println("$num is a Positive Number")num< 0 -> println("$num is a Negative Number")else -> println("Entered Number is Zero")} }Output
輸出量
Run 1: Enter Integer Number : -10 Using if else... -10 is a Negative Number Using when statement... -10 is a Negative Number----Run 2: Enter Integer Number : 10 Using if else... 10 is a Positive Number Using when statement... 10 is a Positive Number---- Run 2: Enter Integer Number : 0 Using if else... Entered Number is Zero Using when statement... Entered Number is Zero翻譯自: https://www.includehelp.com/kotlin/check-whether-given-number-is-positive-negative-or-zero.aspx
kotlin 判斷數字
總結
以上是生活随笔為你收集整理的kotlin 判断数字_Kotlin程序检查给定数字是正数,负数还是零的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 长虹电视是那里生产的?
- 下一篇: scala字符串替换_如何在Scala中