Advertisement
milen_vm

Variant5 Triangle

May 19th, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class Triangle {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner input = new Scanner(System.in);
  8.         int xA = input.nextInt();
  9.         int yA = input.nextInt();
  10.         int xB = input.nextInt();
  11.         int yB = input.nextInt();
  12.         int xC = input.nextInt();
  13.         int yC = input.nextInt();
  14.        
  15.         double distAB = getDistance(xA, yA, xB, yB);
  16.         double distAC = getDistance(xA, yA, xC, yC);
  17.         double distBC = getDistance(xB, yB, xC, yC);
  18.        
  19.         if( distAB + distAC > distBC &&
  20.             distAC + distBC > distAB &&
  21.             distBC + distAB > distAC){
  22.            
  23.             System.out.println("Yes");
  24.             System.out.printf("%.2f", getArea(distAB, distAC, distBC));
  25.         }else {
  26.             System.out.println("No");
  27.             System.out.printf("%.2f", distAB);
  28.         }
  29.        
  30.     }
  31.  
  32.     private static double getDistance(int xA, int yA, int xB, int yB) {
  33.         double dist = Math.sqrt((double)Math.pow((xB - xA), 2) + (double)Math.pow((yB - yA), 2));
  34.         return dist;
  35.     }
  36.  
  37.     private static double getArea(double distAB, double distAC, double distBC) {
  38.         double p = (distAB + distAC + distBC) / 2;
  39.         double area = Math.sqrt(p * (p - distAB) * (p - distAC) * (p - distBC));
  40.         return area;
  41.     }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement