Q:

Kotlin program to print the multiplication table of given number

belongs to collection: Kotlin Basic Programs

0

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.

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Kotlin Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Kotlin program to calculate simple interest... >>
<< Kotlin program to check leap year...