kotlin 计算平方_Kotlin程序计算自然数之和
kotlin 计算平方
Given a number number, and we have to calculate the sum of all natural numbers from 1 to number.
鉴于一些数字 ,我们必须从1计算所有自然数的总和数量 。
Example:
例:
Input:
number = 15
Output:
120
用于计算Kotlin中自然数之和的程序 (Program to calculate the sum of natural numbers 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 integer number
print("Enter Number : ")
val number: Int = scanner.nextInt()
var sum=0
//Iterate through loop to calculate sum
for(i in 1..number){
sum+=i
}
//Print Sum
println("Sum of All Natural Numbers up to $number are : $sum")
}
Output
输出量
Run 1:
Enter Number : 15
Sum of All Natural Numbers up to 15 are : 120
---
Run 2:
Enter Number : 99
Sum of All Natural Numbers up to 99 are : 4950
---
Run 3:
Enter Number : 456
Sum of All Natural Numbers up to 456 are : 104196
翻译自: https://www.includehelp.com/kotlin/calculate-the-sum-of-natural-numbers.aspx
kotlin 计算平方
kotlin 计算平方_Kotlin程序计算自然数之和相关推荐
- kotlin 计算平方_Kotlin程序来计算复利
kotlin 计算平方 Compound interest is the sum of principal amount and interest of interest. 复利是本金和利息之和. G ...
- 复利计算计算器_C程序计算复利
复利计算计算器 Here you will get C program to calculate compound interest. 在这里,您将获得C程序来计算复利. The program as ...
- kotlin 判断数字_Kotlin程序可以逆转数字
kotlin 判断数字 Given an integer number, we have to find reverse number and print it. 给定一个整数,我们必须找到反向数字并 ...
- kotlin 尾递归阶乘_Kotlin程序查找数字的阶乘
kotlin 尾递归阶乘 Factorial of number is the product of all positive numbers less or equal to the number. ...
- kotlin 覆盖属性_Kotlin程序| 方法覆盖的示例
kotlin 覆盖属性 方法重载 (Method Overriding) Method overriding allows derived class has the same function na ...
- kotlin 或 运算_Kotlin程序对两个数字执行算术运算
kotlin 或 运算 Here, we are implementing a Kotlin program to perform various arithmetic operations on t ...
- kotlin字符串数组_Kotlin程序读取,遍历,反向和排序字符串数组
kotlin字符串数组 Given a string array, we have to read, traverse, reverse and sort its elements. 给定一个字符串数 ...
- kotlin获取属性_Kotlin程序| 属性获取器和设置器方法的示例
kotlin获取属性 属性获取器和设置器方法 (Properties Getter and Setter Methods) Variable having a class-level scope, d ...
- kotlin实现继承_Kotlin程序| 继承的例子
kotlin实现继承 遗产 (Inheritance) Inheritance is a mechanism wherein a new class is derived from an existi ...
最新文章
- 效果广告点击率预估实践:在线学习
- Pyhton学习——Day9
- SAP CRM WebClient UI Search against extension field
- mysql002创建表
- python数据分析_使用Python进行数据分析
- vue-cli学习入门_byKL
- mybatis #与$区别
- tp-link tl-wr740n 虚拟服务器,TP-Link TL-WR740N无线wifi无线桥接怎么设置 | tplogin.cn
- JS函数式编程——来源freecodecamp
- shader篇-漫反射
- 空白脂质体冻干粉制备以及荧光素修饰空白脂质体的应用
- 作为互联网人,这些潮流词汇你懂吗?
- JavaScript:实现给定一个句子,返回出现次数最多的单词算法(附完整源码)
- 茶与健康不得不说的话题
- 用计算机管理员同步一下文件,《计算机应用基础(Windows 7 Office 2010)同步训练》0711.docx...
- 44 - 操作MySQL数据库
- 企业微信小程序wx.qy.login 的调用调试踩坑
- 首个搭载鸿蒙系统的手机,抢先P50,首款搭载鸿蒙系统的华为手机即将上市,是一款4G手机...
- 4.19黄金白银TD纸白银行情如何把握,最新行情策略
- 2019年端午节书法作品集