Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- /**
- * Created by simonradev on 23-Dec-16.
- */
- public class TriangleArea {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int[][] coordinates = new int[3][2];
- int lenOfMatrice = coordinates.length;
- for (int i = 0; i < lenOfMatrice; i++) {
- String[] currCoordinates = scan.nextLine().toString().split(" ");
- for (int j = 0; j < 2; j++) {
- coordinates[i][j] = (Integer.parseInt(currCoordinates[j]));
- }
- }
- double areaOfTriangle = Math.round(calculateTheArea(coordinates));
- System.out.printf("%.0f", areaOfTriangle);
- }
- private static double calculateTheArea(int[][] coordinates) {
- double areaToReturn = Math.abs(coordinates[0][0]*(coordinates[1][1] - coordinates[2][1]) +
- coordinates[1][0]*(coordinates[2][1] - coordinates[0][1]) +
- coordinates[2][0]*(coordinates[0][1] - coordinates[1][1])) / 2.0;
- return areaToReturn;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment