Advertisement
velio84

_02_TriangleArea

Sep 8th, 2014
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. package Homework2;
  2. import java.util.Scanner;
  3.  
  4. public class TriangleArea {
  5.  
  6.     public static void main(String[] args) {
  7.        
  8.         Scanner sc = new Scanner(System.in);
  9.        
  10.         System.out.print("Enter Ax: ");
  11.         int Ax = sc.nextInt();
  12.         System.out.print("Enter Ay: ");
  13.         int Ay = sc.nextInt();
  14.         System.out.print("Enter Bx: ");
  15.         int Bx = sc.nextInt();
  16.         System.out.print("Enter By: ");
  17.         int By = sc.nextInt();
  18.         System.out.print("Enter Cx: ");
  19.         int Cx = sc.nextInt();
  20.         System.out.print("Enter Cy: ");
  21.         int Cy = sc.nextInt();
  22.        
  23.         double area = Math.abs( (Ax * (By - Cy) + Bx * (Cy - Ay) + Cx * (Ay-By) ) / 2.0);
  24.        
  25.         if (area == 0) {
  26.             System.out.println("0");
  27.         }
  28.         else {
  29.             System.out.println("The area of this triangle is: " + (int)area);
  30.         }
  31.  
  32.     }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement