Calculate Third side of Triangle puzzle?
Given two sides with length 7 cm and 9 cm and angle between them is 25 degrees. Calculate the third side length of the triangle.
Solution:

Mathematical proof:
Based on the data given , you can calculate the height of the triangle as shown in the above figure.
b side can be split into acosθ and b- acosθ
Applying law of right angled triangle
Expanding the terms we get:
Replace the terms, we get:
Java Program
package com.testingdocs.examples;
public class TriangleThirdSide {
double a;
double b;
double angle;
public TriangleThirdSide(double a, double b, double angle) {
this.a=a;
this.b=b;
this.angle=angle * Math.PI /180;
}
public double findC() {
return Math.sqrt( a*a + b*b - (2*a*b* Math.cos(angle)));
}
public static void main(String[] args) {
TriangleThirdSide triangle= new TriangleThirdSide(7.0,9.0,25.0);
double c = triangle.findC();
System.out.println("Third side of the Triangle = "+ String.format( "%.2f", c ) + " cm");
}
}
Answer:
Third side of the Triangle = 3.98 cm
public TriangleThirdSide(double a, double b, double angle) {
this.a=a;
this.b=b;
this.angle=angle * Math.PI /180;
}
The class constructor takes the values of known sides a , b and the angle between the sides i.e θ . We can create a new Triangle using the new operator as shown below:
Example : new TriangleThirdSide(7.0,9.0,25.0);
Method findC() calculates the third side using the mathematical proof and the formula shown above.