Java Program to print Multiplication Tables

Here is a Java program to print the first ten rows of the multiplication table of a given number.

public class MultiplicationTables {

    public void print(int n) {
        for (int i = 1; i <= 10; i++) {
            int result = n * i;
            System.out.println(n + " * " + i + " = " + result);
        }
    }
}

The method takes an integer n – the number whose tables are to be printed. We have a for loop whose loop counter i runds from 1 to 10. During each iteration of the loop, a row of the multiplication table is printed. The varaible result holds the product for the row that is printed in that iteration.

Sample Execution :

Input :
n = 3

Output :
3 * 1 = 3
3 * 2 = 6
3 * 3 = 9
3 * 4 = 12
3 * 5 = 15
3 * 6 = 18
3 * 7 = 21
3 * 8 = 24
3 * 9 = 27
3 * 10 = 30

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>