Computer Science, asked by smitachatterjee98, 7 months ago

Write the expression in java: Area = √s(s-a)(s-b)(s-c)​

Answers

Answered by samarendradas6969
9

Answer:

Write a Java Program to find Area of a Triangle with an example. If we know the length of three sides of a triangle, we can calculate the area of a triangle using Heron’s Formula:

Area of a Triangle = √(s*(s-a)*(s-b)*(s-c))

Where s = (a + b + c)/2 (Here s = semi perimeter and a, b, c are the three sides of a triangle)

Perimeter of a Triangle = a + b + c

Java Program to find Area of Triangle and Perimeter of Triangle

This Java program allows the user to enter three sides of the triangle. Using those values, we will calculate the Perimeter of a triangle, Semi Perimeter of a triangle, and then Area of a Triangle.

// Java Program to find Area of Triangle and Perimeter of a Triangle

package Area;

import java.util.Scanner;

public class AreaOfTriangle {

private static Scanner sc;

public static void main(String[] args) {

double a, b, c, Perimeter, s, Area;

sc = new Scanner(System.in);

System.out.println("\n Please Enter Three sides of triangle: ");

a = sc.nextDouble();

b = sc.nextDouble();

c = sc.nextDouble();

Perimeter = a + b + c;

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

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

System.out.format("\n The Perimeter of Traiangle = %.2f\n", Perimeter);

System.out.format("\n The Semi Perimeter of Traiangle = %.2f\n",s);

System.out.format("\n The Area of triangle = %.2f\n",Area);

}

}

OUTPUT

Java Program to find Area Of Triangle 1

ANALYSIS

Within the following statements, System.out.println statement will ask the user to enter the three sides of the triangle a, b, c. Next, we are assigning those users value to a, b and c

System.out.println("\n Please Enter Three sides of triangle: ");

a = sc.nextDouble();

b = sc.nextDouble();

c = sc.nextDouble();

In the next Java line, we used a mathematical formula to calculate the Perimeter of the Triangle using the formula P = a + b + c.

Perimeter = a + b + c;

Next, we are calculating the semi perimeter using the formula (a + b + c) / 2. Although we can write semi perimeter = (Perimeter/2) but we want to show the formula behind. That’s why we used the standard formula

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

Next, we are calculating the area of a triangle using Heron’s Formula. Here Math.sqrt() is the math function, which is to calculate the square root.

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

Java Program to find Area of Triangle using functions

This Java program allows the user to enter three sides of the triangle. We will pass those three values to the function arguments to calculate the area of a triangle.

// Java Program to find Area of Triangle using functions

package Area;

import java.util.Scanner;

public class AreaOfTriangleUsingMethods {

private static Scanner sc;

private static double Area;

public static void main(String[] args) {

double a, b, c;

sc = new Scanner(System.in);

System.out.println("\n Please Enter Three sides of triangle: ");

a = sc.nextDouble();

b = sc.nextDouble();

c = sc.nextDouble();

Area = AreaofaTriangle(a, b, c);

System.out.format("\n The Area of triangle = %.2f\n",Area);

}

public static double AreaofaTriangle( double a, double b, double c ) {

double s;

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

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

return Area;

}

}

In this example, We declared the static function of double type with three arguments. By using those arguments, this function will calculate the area of trangel...

Similar questions