- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes

- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages

- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation

- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples

# How To Find Minimum Height of the Triangle with Given Base and Area in Java?

We have the area of triangle ‘a’ and base ‘b’. As per problem statement we have to find the minimum height ‘h’ by using Java programming language.

As we know area of triangle, when base and height are given −

$$\mathrm{area \:=\: \frac{1}{2}\: * \:base\: *\: height}$$

By using above formula, we can get height from it −

height = (2 * area) / base

Then by using the inbuilt **ceil() **method we can get the minimum height.

## To show you some instances

### Instance-1

Suppose, given area = 12 and base = 6

Then by using the formula to get height,

Minimum height = 4.0

### Instance-2

Suppose, given area = 8 and base = 4

Then by using the formula to get height,

Minimum height = 4.0

### Instance-3

Suppose, given area = 12 and base = 5

Then by using the formula to get height,

Minimum height = 5.0

## Syntax

In java, we have **Math.ceil()** method which is used to get the rounded value to the nearest mathematical integer(means smallest integer) which is greater than or equal to the given floating point number.

Below is the syntax for that.

Math.ceil(double value);

## Algorithm

**Step 1**− Get the area and base value of the triangle either by initialization or by user input.**Step 2**− Calculate the height by using the formula.**Step 3**− Then find the minimum height by using Math.ceil() method.**Step 4**− Print the result.

## Multiple Approaches

We have provided the solution in different approaches.

By Using Static Input Value

By Using User Defined Method

Let’s see the program along with its output one by one.

### Approach-1: By Using User Static Value

In this approach the base and area value of the triangle will be declared in the program then by using the algorithm find the minimum height of the triangle.

#### Example

import java.util.*; import java.io.*; public class Main { //main method public static void main(String args[]){ //Declared the area of triangle double area = 6; System.out.println("Area of triangle: "+area); //Declared the base of triangle double base = 14; System.out.println("Base of triangle: "+base); //Find height of triangle double height = (2 * area) / base; System.out.println("Height: " + height); //Find minimum height of triangle by using ceil() method double minHeight = Math.ceil(height); System.out.println("Minimum height: " + minHeight); } }

#### Output

Area of triangle: 6.0 Base of triangle: 14.0 Height: 0.8571428571428571 Minimum height: 1.0

### Approach-2: By Using User Defined Method

In this approach the base and area value of the triangle will be declared in the program. Then call a user defined method by passing this base and area as parameters.

Inside the method, find the minimum height of the triangle by using formula.

#### Example

import java.util.*; import java.io.*; public class Main{ //main method public static void main(String args[]){ //Declared the area of triangle double area = 12; System.out.println("Area of triangle: "+area); //Declared the base of triangle double base = 6; System.out.println("Base of triangle: "+base); //calling a user defined method findHeight(area,base); } //user defined method public static void findHeight(double area, double base){ //Find height of triangle double height = (2 * area) / base; System.out.println("Height: " + height); //Find minimum height of triangle by using ceil() method double minHeight = Math.ceil(height); System.out.println("Minimum height: " + minHeight); } }

#### Output

Area of triangle: 12.0 Base of triangle: 6.0 Height: 4.0 Minimum height: 4.0

In this article, we explored how to calculate the minimum height of the triangle when base and area are given in Java by using different approaches.

- Related Articles
- Minimum height of a triangle with given base and area in C++
- The base and the height of triangle is 25 cm and 3 cm. Find the area of the triangle.
- Find the height of the triangle whose base length is $22 cm$ and area is $170.5 cm^2$.
- Find the base of given triangle."\n
- Find the missing elements of the following parallelograms based on the information provided.a) Area =121.5 m2, base =16.2m, height =?b) Area =395cm2, height =12.5 cm, base =?c) Area =351 m2, base =15.6 m, height =?d) Area 4440 cm2, height =74 cm, base =?
- Find minimum area of rectangle with given set of coordinates in C++
- Find the curved surface area of a cone with base radius $5.25 cm$ and slant height $10 cm$.
- Java program to find the area of a triangle
- How to find the area of the triangle?
- The perimeter of an isosceles triangle is $42 cm$ and its base is ($frac{3}{2}) times each of the equal sides. Find the length of each side of the triangle, area of the triangle and the height of the triangle.
- A triangle and a parallelogram have the same base and the same area. If the sides of triangle are 26 cm, 28 cm and 30 cm, and the parallelogram stands on the base 28 cm, find the height of the parallelogram.
- A triangle and a parallelogram have the same base and the same area. If the sides of the triangle are $13 cm, 14 cm$ and $15 cm$ and the parallelogram stands on the base $14 cm$, find the height of the parallelogram.
- Find the area of the triangle formed by joining the mid-points of the sides of the triangle whose vertices are $(0, -1), (2, 1)$ and $(0, 3)$. Find the ratio of this area to the area of the given triangle.
- The height of a cone is $21 cm$. Find the area of the base if the slant height is $28 cm$.
- Find the height of a rhombus whose area is $168 dm$ and the corresponding base is $21 dm$.