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程序计算自然数之和相关推荐

  1. kotlin 计算平方_Kotlin程序来计算复利

    kotlin 计算平方 Compound interest is the sum of principal amount and interest of interest. 复利是本金和利息之和. G ...

  2. 复利计算计算器_C程序计算复利

    复利计算计算器 Here you will get C program to calculate compound interest. 在这里,您将获得C程序来计算复利. The program as ...

  3. kotlin 判断数字_Kotlin程序可以逆转数字

    kotlin 判断数字 Given an integer number, we have to find reverse number and print it. 给定一个整数,我们必须找到反向数字并 ...

  4. kotlin 尾递归阶乘_Kotlin程序查找数字的阶乘

    kotlin 尾递归阶乘 Factorial of number is the product of all positive numbers less or equal to the number. ...

  5. kotlin 覆盖属性_Kotlin程序| 方法覆盖的示例

    kotlin 覆盖属性 方法重载 (Method Overriding) Method overriding allows derived class has the same function na ...

  6. kotlin 或 运算_Kotlin程序对两个数字执行算术运算

    kotlin 或 运算 Here, we are implementing a Kotlin program to perform various arithmetic operations on t ...

  7. kotlin字符串数组_Kotlin程序读取,遍历,反向和排序字符串数组

    kotlin字符串数组 Given a string array, we have to read, traverse, reverse and sort its elements. 给定一个字符串数 ...

  8. kotlin获取属性_Kotlin程序| 属性获取器和设置器方法的示例

    kotlin获取属性 属性获取器和设置器方法 (Properties Getter and Setter Methods) Variable having a class-level scope, d ...

  9. kotlin实现继承_Kotlin程序| 继承的例子

    kotlin实现继承 遗产 (Inheritance) Inheritance is a mechanism wherein a new class is derived from an existi ...

最新文章

  1. 效果广告点击率预估实践:在线学习
  2. Pyhton学习——Day9
  3. SAP CRM WebClient UI Search against extension field
  4. mysql002创建表
  5. python数据分析_使用Python进行数据分析
  6. vue-cli学习入门_byKL
  7. mybatis #与$区别
  8. tp-link tl-wr740n 虚拟服务器,TP-Link TL-WR740N无线wifi无线桥接怎么设置 | tplogin.cn
  9. JS函数式编程——来源freecodecamp
  10. shader篇-漫反射
  11. 空白脂质体冻干粉制备以及荧光素修饰空白脂质体的应用
  12. 作为互联网人,这些潮流词汇你懂吗?
  13. JavaScript:实现给定一个句子,返回出现次数最多的单词算法(附完整源码)
  14. 茶与健康不得不说的话题
  15. 用计算机管理员同步一下文件,《计算机应用基础(Windows 7 Office 2010)同步训练》0711.docx...
  16. 44 - 操作MySQL数据库
  17. 企业微信小程序wx.qy.login 的调用调试踩坑
  18. 首个搭载鸿蒙系统的手机,抢先P50,首款搭载鸿蒙系统的华为手机即将上市,是一款4G手机...
  19. 4.19黄金白银TD纸白银行情如何把握,最新行情策略
  20. 2019年端午节书法作品集

热门文章

  1. IIS-ShortName-Scanner使用
  2. angularjs 利用filter进行表单查询及分页查询
  3. 前端开发:小程序--第一步
  4. CSS中的overflow属性
  5. 微信小程序echarts层级太高
  6. 中国移动MM7 API用户手册(七)
  7. SSH登录太慢(等很久才提示输入密码)的问题
  8. flask 继承模版的基本使用1
  9. .NET使用NPOI读取Word模板并替换关键字并下载
  10. maven2 + tomcat6 + eclipse集成配置