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(System.in);
		
		// 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);
		
		sc.close();
	}
}

Output: 

Enter the width of triangle
22
Enter the height of triangle
15
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.

Comments

Popular Posts from this Blog

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

Add two numbers in Scala - The Coding Shala

Shell Script to Create a Simple Calculator - The Coding Shala

Goal Parser Interpretation LeetCode Solution - The Coding Shala

New Year Chaos Solution - The Coding Shala