日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

kotlin 判断数字_Kotlin程序检查给定数字是正数,负数还是零

發布時間:2023/12/1 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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程序检查给定数字是正数,负数还是零的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。