본문 바로가기

Algorithm/Language Coder

Jungol (Java) - 616 : 구조체 - 자가진단4

문제

삼각형의 세 꼭지점의 정수 좌표를 입력받아 삼각형의 무게중심의 실수 좌표를 구하여

소수 첫째자리까지 출력하는 프로그램을 작성하시오.

 

입력 예

0 0 1 2 10 15

 

출력 예

(3.7, 5.7)

 

Hint!

세 꼭지점이 (x1 y1), (x2 y2), (x3 y3)인 삼각형의 무게중심 = ((x1+x2+x3)/3 (y1+y2+y3)/3)

 

import java.util.*;

class Triangle {
    int x1, x2, x3, y1, y2, y3;

    public Triangle(double x1, double x2, double x3, double y1, double y2, double y3) {
        x1 = x1;
        x2 = x2;
        x3 = x3;
        y1 = y1;
        y2 = y2;
        y3 = y3;
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double x1, x2, x3, y1, y2, y3;
        x1 = sc.nextDouble();
        y1 = sc.nextDouble();
        x2 = sc.nextDouble();
        y2 = sc.nextDouble();
        x3 = sc.nextDouble();
        y3 = sc.nextDouble();

        System.out.println("(" + Math.round(((x1 + x2 + x3) / 3) * 10.0) / 10.0 + ", "
                + Math.round(((y1 + y2 + y3) / 3) * 10.0) / 10.0 + ")");
    }
}