Advertisement
viraldim

TriangleArea

May 13th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. /*2.Write a program that enters 3 points in the plane (as integer x and y coordinates),
  2. calculates and prints the area of the triangle composed by these 3 points.
  3.  Round the result to a whole number. In case the three points do not form a triangle,
  4. print "0" as result.*/
  5.  
  6. /*Tests:
  7. -5 10 25 30 60 15 ans: 575
  8. 53 18 56 23 24 27 ans: 86
  9. 1 1 2 2 3 3 ans: 0*/
  10. import java.util.Scanner;
  11.  
  12. public class TriangleArea {
  13.  
  14.     public static void main(String[] args) {
  15.         Scanner input = new Scanner(System.in);
  16.         System.out.println("Enter the coords of the triangle!");
  17.         double aX =input.nextDouble();
  18.         double aY =input.nextDouble();
  19.  
  20.         double bX =input.nextDouble();
  21.         double bY =input.nextDouble();
  22.  
  23.         double cX =input.nextDouble();
  24.         double cY =input.nextDouble();
  25.        
  26.         int area = (int)(Math.abs(((aX*(bY-cY))+(bX*(cY-aY))+(cX*(aY-bY)))/2));
  27.         System.out.println("The triangle area is = " + area);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement