Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.23 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package Snajdr;
  7.  
  8. import java.util.*;
  9. import static java.lang.Math.*;
  10.  
  11. /**
  12.  *
  13.  * @author snajpa
  14.  */
  15.  
  16. public class Snajdr {
  17.  
  18.     /**
  19.      * @param args the command line arguments
  20.      */
  21.     public static void main(String[] args) {
  22.         Scanner sc = new Scanner(System.in);
  23.         double[] lengths = {0, 0, 0};
  24.         double[][] coords = {{0,0}, {0,0}, {0,0}};
  25.         System.out.print("Give me a point A (syntax: <number_x> <number_y>: ");
  26.         coords[0][0] = sc.nextDouble();
  27.         coords[0][1] = sc.nextDouble();
  28.         System.out.print("Give me a point B (syntax: <number_x> <number_y>: ");
  29.         coords[1][0] = sc.nextDouble();
  30.         coords[1][1] = sc.nextDouble();
  31.         System.out.print("Give me a point C (syntax: <number_x> <number_y>: ");
  32.         coords[2][0] = sc.nextDouble();
  33.         coords[2][1] = sc.nextDouble();
  34.         lengths[0] = sqrt(pow(coords[0][0]-coords[1][0], 2) +
  35.                         pow(coords[0][1]-coords[1][1], 2));
  36.         lengths[1] = sqrt(pow(coords[1][0]-coords[2][0], 2) +
  37.                         pow(coords[1][1]-coords[2][1], 2));
  38.         lengths[2] = sqrt(pow(coords[2][0]-coords[0][0], 2) +
  39.                         pow(coords[2][1]-coords[0][1], 2));
  40.         Arrays.sort(lengths);
  41.         System.out.println("Triangle properties:");
  42.         if ((lengths[0] + lengths[1]) == lengths[2]) {
  43.             System.out.println("-> Degenerated");
  44.         } else {
  45.             if (sqrt(pow(lengths[0],2) + pow(lengths[1],2)) == lengths[2]) {
  46.                 System.out.println("-> Right");
  47.             }
  48.             if ((lengths[0] == lengths[1]) && (lengths[1] == lengths[2]) &&
  49.                     (lengths[0] == lengths[2])) {
  50.                 System.out.println("-> Equilateral");
  51.             } else if ((lengths[0] == lengths[1]) || (lengths[1] == lengths[2]) ||
  52.                     (lengths[0] == lengths[2])) {
  53.                 System.out.println("-> Isosceles");
  54.             }
  55.         }
  56.         System.out.println("Lengths ascending:");
  57.         System.out.println(lengths[0]);
  58.         System.out.println(lengths[1]);
  59.         System.out.println(lengths[2]);
  60.     }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement