Skip to content

← Back to Overview

Java Program - Multiplication Table

Concept Explanation

What is it?

This program takes an integer input from the user and prints its multiplication table from 1 to 10.


Algorithm

  1. Start
  2. Input a number n.
  3. Start a loop from i = 1 up to 10.
  4. Inside the loop, calculate product = n * i.
  5. Print the result in the format "n * i = product".
  6. End

Implementations

import java.util.Scanner;

public class MultiplicationTable {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter a number: ");
        int n = sc.nextInt();

        System.out.println("Multiplication Table for " + n + ":");
        System.out.println("---------------------------");

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

        sc.close();
    }
}

Complexity Analysis

  • Time Complexity: O(1) - The loop always runs exactly 10 times.
  • Space Complexity: O(1)

Flowchart

graph TD
    A[Start] --> B[Input n]
    B --> C[Initialize i = 1]
    C --> D{i <= 10?}
    D -- Yes --> E[Print n * i]
    E --> F[i = i + 1]
    F --> D
    D -- No --> G[End]


"Repeat until the logic is flawless." - Anonymous