Print multiplication tables for given range

Below is the java source code to print the range of multiplication table.
For an example if you pass the range between 3 to 7 then it will print all the tables starting from 3 until it reaches to 7.
In my case I'm passing two integers 7 and 8 so it will print the multiplication table for 7 and 8.

import java.util.Scanner;

class PrintTables {
    public static void main(String args[]) {
        int firstNumber, secondNumber, range, index;

        System.out
        .println("Enter range of numbers to print their multiplication table");
        Scanner in = new Scanner(System.in);

        firstNumber = in.nextInt();
        secondNumber = in.nextInt();

        for (range = firstNumber; range <= secondNumber; range++) {
            System.out.println("--------------------------");
            System.out.println("Multiplication table of " + range);
            System.out.println("--------------------------");

            for (index = 1; index <= 10; index++) {
                System.out.println(range + "*" + index + " = "
                        + (range * index));
            }
        }
    }
}
Output:
 

1 comment:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here.
    Kindly keep blogging. If anyone wants to become a Java developer learn from Java EE Online Training from India.
    or learn thru Java EE Online Training from India . Nowadays Java has tons of job opportunities on various vertical industry.

    ReplyDelete