

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to Print the Multiplication Table in Triangular Form
In this article, we will understand how to print multiplication table in triangular form. Printing multiplication table in triangular form is achieved using a loop.
Below is a demonstration of the same −
Input
Suppose our input is −
Input : 7
Output
The desired output would be −
The result is : 1 2 4 3 6 9 4 8 12 16 5 10 15 20 25 6 12 18 24 30 36 7 14 21 28 35 42 49
Algorithm
Step 1 - START Step 2 - Declare 3 integer values namely my_input, I and j Step 3 - Read the required values from the user/ define the values Step 4 – Using two for-loops, iterate from 1 to my_input value and calculate the i*j value. Step 5- Display the result 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; import java.util.*; public class MultiplicationTableTrianglePattern { public static void main(String args[]){ int my_input, i, j; 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.println("Enter a number "); my_input = my_scanner.nextInt(); for (i = 1; i <= my_input; i++) { for (j = 1; j <= i; j++) { System.out.print(i * j + " "); } System.out.println(); } } }
Output
Required packages have been imported A reader object has been defined Enter a number 7 1 2 4 3 6 9 4 8 12 16 5 10 15 20 25 6 12 18 24 30 36 7 14 21 28 35 42 49
Example 2
Here, the integer has been previously defined, and its value is accessed and displayed on the console.
import java.util.*; public class MultiplicationTableTrianglePattern { public static void main(String args[]){ int my_input, i, j; System.out.println("Required packages have been imported"); my_input = 7; System.out.println("The number is defined as " +my_input ); for (i = 1; i <= my_input; i++) { for (j = 1; j <= i; j++) { System.out.print(i * j + " "); } System.out.println(); } } }
Output
Required packages have been imported The number is defined as 7 1 2 4 3 6 9 4 8 12 16 5 10 15 20 25 6 12 18 24 30 36 7 14 21 28 35 42 49
- Related Questions & Answers
- Java program to print a multiplication table for any number
- Java Program to Generate Multiplication Table
- Golang Program to Print the Multiplication Table of a Given Number
- C program to print multiplication table by using for Loop
- Java Program to Print Matrix in Z form
- C++ Program to Generate Multiplication Table
- Program to print Lower triangular and Upper triangular matrix of an array in C
- Print multiplication table of a given number in C
- C Program to represent a multiplication table.
- Java program to print a given matrix in Spiral Form.
- Java Program to display upper triangular matrix
- C++ Program to Print Matrix in Z form?
- Python Program to Print Matrix in Z form
- Program to Print the Squared Matrix in Z form in C
- PHP program to print continuous numbers in the form of triangle
Advertisements