Java Program for Triangular Matchstick Number
class Main
{
public static void main(String [] args)
{
//value of 'x' declared
int x = 1;
//finding number of matchstick required to form a triangular pyramid
//Using the formula (3*x*(x+1))/2
int no = (3*x*(x+1))/2;
System.out.println("The number of matchstick required to form a triangular pyramid is: " + no);
}
}
Output:
The number of matchstick required to form a triangular pyramid is: 3
