182k views
1 vote
Java Program for lengths of the sides of a triangle to compute the area using the given equation LaTeX: Area\:=\:\sqrt{s\left(s-a\right)\left(s-b\right)\left(s-c\right)}

1 Answer

2 votes

Answer:

import java.util.Scanner;

public class Area

{

public static void main(String[] args) {

double a, b, c, s, area;

Scanner input = new Scanner(System.in);

System.out.print("Enter three sides of the triangle: ");

a = input.nextDouble();

b = input.nextDouble();

c = input.nextDouble();

s = (a + b + c) / 2;

area = Math.sqrt(s*(s-a)*(s-b)*(s-c));

System.out.print("The area of triangle = " + area);

}

}

Step-by-step explanation:

Define variables for the sides, s, and area.

Ask the user for the side values using Scanner object.

Use the given formula to calculate s.

After calculating s, use the formula to calculate area.

Print the value of area.

User Henu
by
5.8k points