
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Java Program to Generate Multiplication Table
In this article, we will understand how to print a multiplication table. Multiplication table is created by iterating the required input 10 times using a for loop and multiplying the input value with numbers from 1 to 10 in each iteration.
Below is a demonstration of the same −
Input
Suppose our input is −
Input : 16
Output
The desired output would be −
The multiplication table of 16 is : 16 * 1 = 16 16 * 2 = 32 16 * 3 = 48 16 * 4 = 64 16 * 5 = 80 16 * 6 = 96 16 * 7 = 112 16 * 8 = 128 16 * 9 = 144 16 * 10 = 160
Algorithm
Step 1 – START Step 2 – Declare two integer values namely my_input and i. Step 3 - Read the required values from the user/ define the values Step 4 – Iterate from 1 to 10 using a for-loop, and in each iteration, multiply the numbers 1 to 10 with the input. Step 5- Display the resulting value in after each iteration. Step 6- Stop
Example 1
Here, the input is being entered by the user based on a prompt. You can try this example live in ourcoding ground tool .
import java.util.Scanner; public class MultiplicationTable { public static void main(String[] args) { int my_input, i; my_input = 16; System.out.println("Required packages have been imported"); Scanner my_scanner = new Scanner(System.in); System.out.println("A reader object has been defined "); System.out.print("Enter a number : "); my_input = my_scanner.nextInt(); System.out.println("The multiplication table of " +my_input + " is :"); for(i = 1; i <= 10; ++i){ System.out.printf("%d * %d = %d \n", my_input, i, my_input * i); } } }
Output
Required packages have been imported A reader object has been defined Enter a number : 16 The multiplication table of 16 is : 16 * 1 = 16 16 * 2 = 32 16 * 3 = 48 16 * 4 = 64 16 * 5 = 80 16 * 6 = 96 16 * 7 = 112 16 * 8 = 128 16 * 9 = 144 16 * 10 = 160
Example 2
Here, the integer has been previously defined, and its value is accessed and displayed on the console.
public class MultiplicationTable { public static void main(String[] args) { int my_input, i; my_input = 16; System.out.println("The number is defined as " +my_input); System.out.println("The multiplication table of " +my_input + " is :"); for(i = 1; i <= 10; ++i){ System.out.printf("%d * %d = %d \n", my_input, i, my_input * i); } } }
Output
The number is defined as 16 The multiplication table of 16 is : 16 * 1 = 16 16 * 2 = 32 16 * 3 = 48 16 * 4 = 64 16 * 5 = 80 16 * 6 = 96 16 * 7 = 112 16 * 8 = 128 16 * 9 = 144 16 * 10 = 160
- Related Articles
- C++ Program to Generate Multiplication Table
- Swift Program to Generate Multiplication Table
- Haskell Program to Generate Multiplication Table
- Kotlin Program to Generate Multiplication Table
- Java program to print a multiplication table for any number
- Java Program to Print the Multiplication Table in Triangular Form
- C Program to represent a multiplication table.
- C program to print multiplication table by using for Loop
- Haskell Program to Print the Multiplication Table in Triangular Form
- C++ Program to Print the Multiplication Table in Triangular Form
- Java program to generate random numbers
- Golang Program to Print the Multiplication Table of a Given Number
- Java Program to generate random numbers string
- Java program for Multiplication of Array elements.
- Java program to generate and print Floyd’s triangle

Advertisements