Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2015
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. package Homework;
  2. import java.awt.Point;
  3. import java.util.Scanner;
  4.  
  5. public class TriangleArea {
  6. public static void main(String[] args) {
  7. Scanner reader = new Scanner(System.in);
  8. Point pointA = new Point(reader.nextInt(),reader.nextInt());
  9. Point pointB = new Point(reader.nextInt(),reader.nextInt());
  10. Point pointC = new Point(reader.nextInt(),reader.nextInt());
  11.  
  12. System.out.println(TriangleArea(pointA, pointB, pointC));
  13. }
  14.  
  15. private static int TriangleArea(Point pointA, Point pointB, Point pointC) {
  16. //(Ax*(By-Cy)+Bx*(Cy-Ay)+Cx*(Ay-By))/2;
  17. int result = (int) ((pointA.getX()*(pointB.getY()- pointC.getY())+ pointB.getX()*(pointC.getY()-pointA.getY())+pointC.getX()*(pointA.getY()-pointB.getY()))/2);
  18. if (result < 0){
  19. return -result;
  20.  
  21. }
  22. return result;
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement