Area of a triangle with two vertices at midpoints of opposite sides of a square and the other vertex lying on vertex of a square | Java program for the above approach ; Function to find the area of the triangle that inscribed in square ; Stores the length of the first side of triangle ; Stores the length of the second side of triangle ; Stores the length of the third side of triangle ; Stores the area of the triangle ; Return the resultant area ; Driver code
import java . util . * ; class GFG { static double areaOftriangle ( int side ) { double a = Math . sqrt ( Math . pow ( side / 2 , 2 ) + Math . pow ( side / 2 , 2 ) ) ; double b = Math . sqrt ( Math . pow ( side , 2 ) + Math . pow ( side / 2 , 2 ) ) ; double c = Math . sqrt ( Math . pow ( side , 2 ) + Math . pow ( side / 2 , 2 ) ) ; double s = ( a + b + c ) / 2 ; double area = Math . sqrt ( s * ( s - a ) * ( s - b ) * ( s - c ) ) ; return area ; } public static void main ( String [ ] args ) { int N = 10 ; System . out . print ( areaOftriangle ( N ) ) ; } }