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 乘法