Advertisement
M_Andreev

TriangleArea

Sep 7th, 2014
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class _02_TriangleArea {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner sc = new Scanner(System.in);
  7.         System.out.print("Ax: ");
  8.         double ax = sc.nextDouble();
  9.         System.out.print("Ay: ");
  10.         double ay = sc.nextDouble();
  11.        
  12.         System.out.print("Bx: ");
  13.         double bx = sc.nextDouble();
  14.         System.out.print("By: ");
  15.         double by = sc.nextDouble();
  16.        
  17.         System.out.print("Cx: ");
  18.         double cx = sc.nextDouble();
  19.         System.out.print("Cy: ");
  20.         double cy = sc.nextDouble();
  21.        
  22.         double area = (ax * (by - cy) + bx * (cy - ay) + cx * (ay - by)) / 2 ;
  23.        
  24.         if ((ax == ay) && (bx == by) && (cx == cy)) {
  25.             System.out.println(0);
  26.         }
  27.         else {
  28.             System.out.print("Area: " + area);
  29.         }
  30.     }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement