Kali in saya akan membagikan tentang cara menghitung luas segitiga pada pemrograman java, ..
Silahkan dicoba, . .
import java.util.Scanner;
public class AreaOfTriangle {
public static void main(String[] iriahus) {
@SuppressWarnings("resource")
Scanner sc = new Scanner(System.in);
System.out.print("Enter three points for a triangle: ");
double x1 = sc.nextDouble();
double y1 = sc.nextDouble();
double x2 = sc.nextDouble();
double y2 = sc.nextDouble();
double x3 = sc.nextDouble();
double y3 = sc.nextDouble();
double s1 = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
double s2 = Math.sqrt((x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2));
double s3 = Math.sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3));
double s = (s1 + s2 + s3) / 2;
double areaOfTriangle = Math.sqrt(s * (s - s1) * (s - s2) * (s - s3));
System.out.println("The area of triangle is " + areaOfTriangle);
}
}
Semoga bermanfaat, . .
0 Response to "Menghitung Luas Segitiga"
Post a Comment