Objective: Given the base and height of a triangle, using math formula for calculating the area of triangle, write an java program to calculate the triangle area.
Area of a Triangle: (Base * Height)/2
Code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AreaOfTriangleBaseHeight { | |
public static void area(double base, double height){ | |
double area = (base*height)/2; | |
System.out.println("Area of Triangle is: " + area); | |
} | |
public static void main(String[] args) { | |
double base = 4; | |
double height = 5; | |
area(base, height); | |
} | |
} |
Output:
Area of Triangle is: 10.0