Write a Kotlin Program to Generate Multiplication Table

Kotlin is a popular programming language used for developing Android apps, server-side applications, and much more.

In this tutorial, we will show you how to create a Kotlin program to generate multiplication tables.

Multiplication tables are used to display the product of two or more numbers.

They are often used for learning basic mathematics or to help students memorize multiplication facts.

In this program, we will use a nested for loop to generate a multiplication table for a given number.

Let’s take a look at the Kotlin program to generate multiplication tables:

fun main(args: Array<String>) {
    print("Enter a number: ")
    val number: Int = readLine()!!.toInt()

    for (i in 1..10) {
        println("$number * $i = ${number * i}")
    }
}

The program starts by prompting the user to enter a number using the print() function.

The readLine() function reads the input from the user and converts it to an integer using the toInt() function.

Next, we have a for loop that runs from 1 to 10. For each value of i in the loop, we print out the multiplication table using the println() function.

The string interpolation is used to print out the value of the multiplication table for each value of i.

When you run the program and enter a number, the output will look something like this:

Enter a 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

In conclusion, Kotlin is a powerful programming language that is well-suited for a wide range of applications.

In this article, we have shown you how to create a program to generate multiplication tables using Kotlin’s for loop and string interpolation.

We hope you find this article helpful as you explore the world of Kotlin programming.