kotlin 乘法_Kotlin程序打印给定数字的乘法表

kotlin 乘法

Given an integer number, we have to print its multiplication table.

给定一个整数,我们必须打印其乘法表。

To print a multiplication table, we run a loop starting from 1 to 10 and print the multiplication of the number with the loop variable/counter.

要打印一个乘法表,我们运行一个从1到10的循环,并打印数字与循环变量/计数器的乘法。

In the below program, we are creating a Kotlin program for printing the multiplication table.

在下面的程序中,我们将创建一个Kotlin程序来打印乘法表

程序在Kotlin中打印乘法表 (Program to print the multiplication table in Kotlin)

package com.includehelp.basic

import java.util.*

// Main function entry point of program
fun main(args: Array<String>) {

    val sc = Scanner(System.`in`)
    println("Enter Number: ")
    val num: Int = sc.nextInt() 

    // for loop to print multiplication table of given number
    for (i in 1..10) {
        val result = num * i
        println("$num*$i = $result")
    }
}

Output

输出量

Enter Number:
5
5*1 = 5
5*2 = 10
5*3 = 15
5*4 = 20
5*5 = 25
5*6 = 30
5*7 = 35
5*8 = 40
5*9 = 45
5*10 = 50
------
Run 2:
Enter Number:
12
12*1 = 12
12*2 = 24
12*3 = 36
12*4 = 48
12*5 = 60
12*6 = 72
12*7 = 84
12*8 = 96
12*9 = 108
12*10 = 120


翻译自: https://www.includehelp.com/kotlin/print-the-multiplication-table-of-given-number.aspx

kotlin 乘法

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值