Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Farahim Ibrahimli
- * Homework 1 Question 5
- *
- */
- import java.util.Scanner;
- public class Question5 {
- private static Scanner in = new Scanner(System.in);
- public static double readDouble(String prompt) {
- System.out.print(prompt);
- return in.nextDouble();
- }
- public static double calculateDistance(double startX, double startY, double endX, double endY) {
- return Math.sqrt(Math.pow(startX - endX, 2) + Math.pow(startY - endY, 2));
- }
- public static void main(String[] args) {
- double aX = readDouble("Enter Point A X-Coordinate: ");
- double aY = readDouble("Enter Point A Y-Coordinate: ");
- double bX = readDouble("Enter Point B X-Coordinate: ");
- double bY = readDouble("Enter Point B Y-Coordinate: ");
- double cX = readDouble("Enter Point C X-Coordinate: ");
- double cY = readDouble("Enter Point C Y-Coordinate: ");
- double aToB = calculateDistance(aX, aY, bX, bY);
- double bToC = calculateDistance(bX, bY, cX, cY);
- double cToA = calculateDistance(cX, cY, aX, aY);
- if((aToB + bToC > cToA) || (bToC + cToA > aToB) || (cToA + aToB > bToC)) {
- System.out.println("It is a real triangle");
- } else {
- System.out.println("It is a fake triangle");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement