Java Program to Find Maximum Number of Squares That Can Fit in a Right-Angle Isosceles Triangle
public class Main
{
public static void main(String[] args)
{
// Static values for the side of the triangle and the side of the square
int height = 6, square = 2;
System.out.println("The number of squares which can be fit into the triangle are: "+maxSquare(height,square));
}
// Function that uses recursion to find out the number of squares
// which can fit inside the triangle
static int maxSquare(int h, int s)
{
return (h/s-1)*(h/s)/2;
}
}
Output:
The number of squares which can be fit into the triangle are: 3
