kotlin 取整数
Given an integer N, we have to count total number of digits.
给定整数N ,我们必须计算数字的总数 。
Example:
例:
Input:
N = 123
Output:
Total digits: 3
Input:
N = 12345
Output:
Total digits: 5
程序在Kotlin中对数字中的数字进行计数 (Program to count digits in a number in Kotlin)
package com.includehelp.basic
import java.util.*
// Main Function entry Point of Program
fun main(args: Array<String>) {
// Input Stream
val scanner = Scanner(System.`in`)
// Input number
println("Enter Number : ")
var number: Long = scanner.nextLong()
var count=0
// Count Number of Digits in numbers
while (number>0){
number/=10
count++
}
// print count
println("Number of Digits : $count")
}
Output
输出量
Run 1:
Enter Number :
2343434544
Number of Digits : 10
-------
Run 2:
Enter Number :
123456
Number of Digits : 6
翻译自: https://www.includehelp.com/kotlin/count-digits-in-an-integer.aspx
kotlin 取整数