Java Program to Find Centroid of a Triangle
import java.util.*;
public class Main
{
public static void main(String[] args)
{
//points of the triangle are declared
//point-1
double x1 = 1;
double y1 = 2;
//point-2
double x2 = 3;
double y2 = 4;
//point-3
double x3 = 5;
double y3 = 6;
// formula to find centroid of the triangle
double x = (x1+x2+x3)/2;
double y = (y1+y2+y3)/2;
System.out.println("The centroid of the triangle PQR is (" + x + "," + y + ")");
}
}
Output:
The centroid of the triangle PQR is (4.5, 6.0)
