In the previous article, we have seen Java Program to Check if Triangle is Valid or Not if Sides are Given

In this article we will discuss about how to Find Minimum Height of the Triangle with Given Base and Area using Java programming language.

## Java Program to Find Minimum Height of the Triangle with Given Base and Area

Before jumping into the program directly, let’s first know how can we Find Minimum Height of the Triangle with Given Base and Area.

**Explanation:**

Formula to Find Minimum Height of the Triangle with Given Base and Area: (2*area)/base

**Example:**

When area=40 and base=5 Minimum height: (2*area)/base => (2*40)/5 => 80/5 => 16

Let’s see different ways to find minimum height of the triangle with given base and area.

### Method-1: Java Program to Find Minimum Height of the Triangle with Given Base and Area By Using Static Value

**Approach:**

- Declare the value for ‘base’ and ‘area’.
- Use the formula
`(2*area)/base`

to calculate the minimum height of the triangle. - Round the minimum height to the next nearest round number,
- Then print the result.

**Program:**

// JAVA Code to Find Minimum Height of the Triangle with Given Base and Area By User Input Value import java.util.Scanner; public class Main { public static void main(String[] args) { // Static values double base = 20, area= 100; // Calculating the minimum height of the triangle double minHeight = (2*area)/base; // Rouding it to the next whole number minHeight = Math.ceil(minHeight); System.out.println("The minimum height of the triangle is "+minHeight); } }

Output: The minimum height of the triangle is 10.0

### Method-2: Java Program to Find Minimum Height of the Triangle with Given Base and Area By User Input Value

**Approach:**

- Take user input the value for ‘base’ and ‘area’.
- Use the formula
`(2*area)/base`

to calculate the minimum height of the triangle. - Round the minimum height to the next nearest round number,
- Then print the result.

**Program:**

// JAVA Code to Find Minimum Height of the Triangle with Given Base and Area By User Input Value import java.util.Scanner; public class Main { public static void main(String[] args) { // Takes base and area as input fro the user Scanner scan = new Scanner(System.in); System.out.println("Enter the base and area of the triangle"); double base = scan.nextDouble(), area = scan.nextDouble(); // Calculating the minimum height of the triangle double minHeight = (2*area)/base; // Rounding it to the next whole number minHeight = Math.ceil(minHeight); System.out.println("The minimum height of the triangle is "+minHeight); } }

Output: Enter the base and area of the triangle 5 100 The minimum height of the triangle is 40.0

Want to excel in java coding? Practice with these Java Programs examples with output and write any kind of easy or difficult programs in the Java language.

**Related Java Articles:**