Write an application that reads the lengths of the sides of a triangle from the user. compute the area of the triangle using heron's formula (below), in which s represents half of the perimeter of the triangle and a, b, and c represent the lengths of the three sides. print the area rounded to three decimal places.

Respuesta :

Here you go,


import java.util.Scanner;

import java.util.Random;

public class OrderCalculator{


public static void main(String[] args){  


float x, y, z, semi, area;

Scanner in = new Scanner(System.in);

System.out.print("Enter the 3 sides: ");

x = in.nextFloat();

y = in.nextFloat();

z = in.nextFloat();

semi = (float) ((x + y + z) / 2.0);

area = (float) Math.sqrt(semi * (semi - x) * (semi - y) * (semi - z));

System.out.printf("The area is: %.3f\n", area);


}

}

Otras preguntas