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
- Start
- Input a number
n. - Start a loop from
i = 1up to10. - Inside the loop, calculate
product = n * i. - Print the result in the format "n * i = product".
- End
Implementations
- Java (JDK 17)
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
Related Concepts
"Repeat until the logic is flawless." - Anonymous