# Calculate Area of Triangle in Java

## 2 Ways To Calculate Area of Triangle in Java

Here, we have described Two Methods To Calculate Area of Triangle in Java Programming Language. Java Code To Find Area of Triangle using Parameters with a self-explanatory program.

#### Area of Triangle = 0.5 * Base * Height

#### Method 1: Calculate Area of Triangle in Java without Parameters

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import java.io.*; class Triangle { double base, height; double area() { return (0.5 * base * height); } } class Area { public static void main(String args[]) { double area; Triangle rec1 = new Triangle(); rec1.base = 20; rec1.height = 30; area = rec1.area(); System.out.println("\nArea of Triangle: " + area + "\n"); } } |

**Also Read: Calculate Area of Rectangle Java Program**

#### Method 2: Find Area of Triangle Java Program with Parameters

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | import java.io.*; class Triangle { double base, height; double area() { return (0.5 * base * height); } void value(double b,double h) { base = b; height = h; } } class Area { public static void main(String args[]) { double area; Triangle rec1 = new Triangle(); rec1.value(20, 30); area = rec1.area(); System.out.println("\nArea of Triangle: " + area + "\n"); } } |

**Also Read: Java Program To Check Public IP Address**

#### Output

In case you get any Compilation Errors with this Code To Calculate Area of Triangle in Java or if you have any doubt about it, mention it in the Comment Section.