Count of Equilateral Triangles of unit length possible from a given Hexagon | Java program to implement the above approach ; Function to calculate the the number of Triangles possible ; Driver Code ; Regular Hexagon ; Irregular Hexagon
import java . util . * ; class GFG { static int calculateTriangles ( int sides [ ] ) { double count = Math . pow ( sides [ 0 ] + sides [ 1 ] + sides [ 2 ] , 2 ) ; count -= Math . pow ( sides [ 0 ] , 2 ) ; count -= Math . pow ( sides [ 2 ] , 2 ) ; count -= Math . pow ( sides [ 4 ] , 2 ) ; return ( int ) ( count ) ; } public static void main ( String [ ] args ) { int sides [ ] = { 1 , 1 , 1 , 1 , 1 , 1 } ; System . out . print ( ( calculateTriangles ( sides ) ) + "NEW_LINE"); int sides1 [ ] = { 2 , 2 , 1 , 3 , 1 , 2 } ; System . out . print ( ( calculateTriangles ( sides1 ) ) + "NEW_LINE"); } }