Given a number X which represents the floor of a matchstick pyramid, write a program to print the total number of matchstick required to form a pyramid of matchsticks of x floors.
Examples:
Input : X = 1 Output : 3 Input : X = 2 Output : 9
This is mainly an extension of triangular numbers. For a number X, the matchstick required will be three times of X-th triangular numbers, i.e., (3*X*(X+1))/2

// Java program to find X-th triangular // matchstick number public class TriangularPyramidNumber { public static int numberOfSticks(int x) { return (3 * x * (x + 1)) / 2; } public static void main(String[] args) { System.out.println(numberOfSticks(7)); } } |
chevron_right
filter_none
Output:
84
Please refer complete article on Triangular Matchstick Number for more details!
Recommended Posts:
- Java Program for How to check if a given number is Fibonacci number?
- Java Program to Find the Number Occurring Odd Number of Times
- Java Program for Program to calculate area of a Tetrahedron
- Java Program for Program to find area of a circle
- Java Program for Program for array rotation
- Java Program for nth multiple of a number in Fibonacci Series
- Java Program for Largest K digit number divisible by X
- Java Program for Smallest K digit number divisible by X
- Java Program for Number of stopping station problem
- Java Program for Print Number series without using any loop
- Java Program to Check if all digits of a number divide it
- Java Program to check whether it is possible to make a divisible by 3 number using all digits in an array
- Java Program to Find sum of even factors of a number
- Java Program to Find minimum sum of factors of number
- Java Program for Find largest prime factor of a number
- Java Program for Number of elements with odd factors in given range
- Java Program for efficiently print all prime factors of a given number
- Java Program to check Armstrong Number
- Java Program for Sum the digits of a given number
- Java Program for factorial of a number

