kotlin 判断数字_Kotlin程序可以逆转数字
kotlin 判断数字
Given an integer number, we have to find reverse number and print it.
给定一个整数,我们必须找到反向数字并打印出来。
Example:
例:
Input:
Number: 12345
Output:
Reverse Number: 54321
To find a reverse number – we use this formula: reverse = (reverse * 10) + lastDigit, to calculate the lastDigit, we find the remainder of the number by dividing the number with 10.
要找到一个反向数字 –我们使用以下公式: reverse =(reverse * 10)+ lastDigit ,要计算lastDigit ,我们可以通过将数字除以10来找到数字的余数。
Consider the below program to find the reverse number.
考虑下面的程序以找到反向编号 。
计划在Kotlin中反转数字 (Program to reverse a number in Kotlin)
package com.includehelp.basic
import java.util.*
/* Function to Reverse an given Integer Number */
fun getReverse(number: Int): Int {
var number = number
var sum = 0
while (number > 0) {
val r = number % 10
sum = sum * 10 + r
number /= 10
}
return sum
}
//Main function Entry Point of Program
fun main(arg: Array<String>) {
val sc = Scanner(System.`in`)
//Input Number
println("Enter Number : ")
val num: Int = sc.nextInt()
//Calling function to get reverse number
val reverseNumber = getReverse(num)
// Print reverse format of number
println("Reverse Number : $reverseNumber")
}
Output
输出量
Run 1:
Enter Number :
12345
Reverse Number : 54321
-------
Run 2:
Enter Number :
345389
Reverse Number : 983543
翻译自: https://www.includehelp.com/kotlin/reverse-a-number.aspx
kotlin 判断数字
kotlin 判断数字_Kotlin程序可以逆转数字相关推荐
- kotlin 或 运算_Kotlin程序对两个数字执行算术运算
kotlin 或 运算 Here, we are implementing a Kotlin program to perform various arithmetic operations on t ...
- kotlin 尾递归阶乘_Kotlin程序查找数字的阶乘
kotlin 尾递归阶乘 Factorial of number is the product of all positive numbers less or equal to the number. ...
- kotlin int最大值_Kotlin程序查找三个数字中的最大值
kotlin int最大值 Input 3 integer numbers, we have to find the largest of these input numbers. 输入3个整数,我们 ...
- kotlin中判断字符串_Kotlin程序查找字符串中字符的频率
kotlin中判断字符串 Given a string and a character, we have to find the frequency of the character in the s ...
- kotlin中判断字符串_Kotlin程序删除字符串中所有出现的字符
kotlin中判断字符串 Given a string and a character, we have to remove all occurrences of the character in g ...
- kotlin 计算平方_Kotlin程序计算自然数之和
kotlin 计算平方 Given a number number, and we have to calculate the sum of all natural numbers from 1 to ...
- kotlin 计算平方_Kotlin程序来计算复利
kotlin 计算平方 Compound interest is the sum of principal amount and interest of interest. 复利是本金和利息之和. G ...
- kotlin 覆盖属性_Kotlin程序| 方法覆盖的示例
kotlin 覆盖属性 方法重载 (Method Overriding) Method overriding allows derived class has the same function na ...
- kotlin字符串数组_Kotlin程序读取,遍历,反向和排序字符串数组
kotlin字符串数组 Given a string array, we have to read, traverse, reverse and sort its elements. 给定一个字符串数 ...
最新文章
- Thttpd manual
- 一个命令让Ubuntu升级变得更简单
- Spring Boot 进行优雅的字段校验,写得太好了!
- feign date类型时间错误问题
- Py之paddlehub:paddlehub的简介、安装、使用方法之详细攻略
- DL之GANDCGNNcGAN:GANDCGNNcGAN算法思路、关键步骤的相关配图和论文集合
- WebBrowser 操作(从网上收集)
- dorado 中的日期--》oracle中的日期
- 关于python文件问题
- Cacti0.8.8a监控mysql
- Spring Cloud Spring Boot mybatis分布式微服务云架构(一)快速入门
- [jQuery] 速记一の屏蔽鼠标右键监听鼠标Event
- python tkinter 定时_如何使用tkinter创建计时器?
- RTMP协议及H264文件格式分析
- 七周成为数据分析师 | Excel
- html 代码实现一些符号,大于号、小于号、商标等
- CleanMyMacX软件怎么样?实际使用效果功能讲解
- 思科Cisco 路由器型号解析
- ipad协议828稳定版
- 将毫秒转换为年月日时分秒
热门文章
- maya导出fbx没动画_Maya学习方法总结
- c语言斐波那契数列_剑指Offer-10-I.斐波那契数列
- SQLPlus命令详细说明
- 【转】AB实验设计思路及实验落地
- Failed to start firewalld.service: Unit firewalld.service is masked.
- JConsole的使用手册 JDK1.5(转)
- open×××+Mysql+PAM构建强大的***系统
- 建立openstack quantum开发环境 .
- 解决wordpress无法离线发布(远程发布)的故障
- (转)解读NTFS(一)