Java Program to Find the Area of Triangle - The Coding Shala
Home >> Java Programs >> Area of Triangle
Other Posts You May Like
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
- Java Program to Reverse a String
- Java Program to Swap Two Numbers
- Java Program to add two numbers
- Java Program to Find Sum of Digits of a Number
- Java Program to Multiply two Numbers
Comments
Post a Comment