# Java Program to calculate Area and Perimeter of Right Triangle

Hello coders, in this post, we will learn Java program to calculate area and perimeter of Right Triangle. In the previous tutorial, you have learned Java program to calculate area of a triangle using Heron’s formula. We can calculate the area and perimeter of the right triangle in Java very easily in just a few lines of code.

So let’s try to know the answer to the query, how do you find the area and perimeter of a right triangle in Java?

But first, let’s know the formula of finding the area and perimeter of a right triangle. Here is the formula.

Area of right triangle = (b*h)/2

Where,

• b is the base of the triangle
• h is the base and height of the triangle.

Perimeter of right triangle = a+b+c

where

• a, b, and c are three sides of the triangle.

Now Let us write the program.

# Java Program to calculate Area and Perimeter of Right Triangle

### What we did?

• First of all we have imported util package.
• Then created a class and named it Triangle.
• After that started main() method of the program.
• Then inside main() method declared variables.
• Then created object of the Scanner class.
• Now asked the user to enter the base and height of the triangle. Then read the value of base and height entered by the user.
• Then calculated area of triangle using the formula area = (base*height)/2.
• In the next line calculated perimeter of triangle using the formula perimeter = a+b+c
• Then finally printed the value of area and perimeter of triangle on the screen.

Output

So guys this was all about Java program to calculate area and perimeter of Right Triangle. In the next tutorial you will learn Java Program to calculate Area and Perimeter of Rectangle.

Related Tutorials…