Java Program to Find the Area of Triangle - The Coding Shala

Home >> Java Programs >> Area of Triangle

 In this post, we will learn how to find the Area of the Triangle using a Java Program.

Java Program to Find Area of Triangle

Write a Java program to find the area of the given triangle.

We base width and the height of the triangle is given then using the area formula we can calculate the area of the given triangle.

Area of Triangle = (base width * height ) / 2

Example 1:
Input: base width: 22
           height: 15
Output: Area: 165

Java Program: 

// Java program to Find Area of Triangle

import java.util.Scanner;

public class Main {
	public static void main(String[] args) { 
		Scanner sc = new Scanner(;
		// take base width input
		System.out.println("Enter the width of triangle");
		double base = sc.nextDouble();
		// take height input
		System.out.println("Enter the height of triangle");
		double height = sc.nextDouble();
		// calculate the area
		// area = (base * height) / 2
		double area = (base * height) / 2;
		System.out.println("Area of Triangle is: " + area);


Enter the width of triangle
Enter the height of triangle
Area of Triangle is: 165.0

Other Posts You May Like
Please leave a comment below if you like this post or found some errors, it will help me to improve my content.


Popular Posts from this Blog

LeetCode - Crawler Log Folder Solution - The Coding Shala

Richest Customer Wealth LeetCode Solution - The Coding Shala

First Unique Character in a String Java - The Coding Shala

Shell Script to find sum, product and average of given numbers - The Coding Shala

Add two numbers in Scala - The Coding Shala