Number of triangles formed by joining vertices of n | Java program to implement the above problem ; Function to find the number of triangles ; print the number of triangles having two side common ; print the number of triangles having no side common ; Driver code ; initialize the number of sides of a polygon
import java . io . * ; class GFG { static void findTriangles ( int n ) { int num = n ; System . out . print ( num + " ▁ " ) ; System . out . print ( num * ( num - 4 ) * ( num - 5 ) / 6 ) ; } public static void main ( String [ ] args ) { int n ; n = 6 ; findTriangles ( n ) ; } }