Java Program for Triangular Matchstick Number Last Updated : 05 Jan, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 = 1Output : 3 Input : X = 2Output : 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 // 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)); } } Output84 Time Complexity: O(1) as it is performing constant operationsAuxiliary Space: O(1) Please refer complete article on Triangular Matchstick Number for more details! Comment More infoAdvertise with us Next Article Java Program to Print Downward Triangle Star Pattern K kartik Follow Improve Article Tags : Java Practice Tags : Java Similar Reads Java Program to Print a Square Pattern for given integer Write a java program to print the given Square Pattern on taking an integer as input from commandline. Examples: Input : 3 Output :1 2 3. 7 8 9 4 5 6 Input :4 Output :1 2 3 4 9 10 11 12 13 14 15 16 5 6 7 8 Java // Java program to print a square pattern with command // line one argument import java.u 2 min read Java Program for N Queen Problem | Backtracking-3 The N Queen is the problem of placing N chess queens on an NÃN chessboard so that no two queens attack each other. For example, the following is a solution for 4 Queen problem. The expected output is a binary matrix which has 1s for the blocks where queens are placed. For example, following is the o 4 min read Tic-Tac-Toe Game in Java Tic-Tac-Toe is a classic game that two people can enjoy together. It is played on a 3x3 grid where players take turns placing their marks, X or O, in empty spots. The main goal is to get three of the same marks in a row-horizontally, vertically, or diagonally.In this article, we are going to build a 7 min read Java Program to Print Downward Triangle Star Pattern Downward triangle star pattern means we want to print a triangle that is downward facing means base is upwards and by default, orientation is leftwards so the desired triangle to be printed should look like * * * * * * * * * * Example Java // Java Program to Print Lower Star Triangle Pattern // Main 2 min read Java Program to Print Star Pascalâs Triangle Pascalâs triangle is a triangular array of the binomial coefficients. Write a function that takes an integer value n as input and prints the first n lines of Pascalâs triangle. Following are the first 6 rows of Pascalâs Triangle.In this article, we will look into the process of printing Pascal's tri 4 min read Java Program to Print the Multiplication Table in a Triangle Form In this form, a table is displayed row and column-wise, in such a way such that in every row, only the entries up to the same column number filled. Example: Input : rows = 6 Output: 1 2 4 3 6 9 4 8 12 16 5 10 15 20 25 6 12 18 24 30 36 Approach: The idea is to use nested loops. First, display the col 2 min read Like