Omar_Natour

Natour, O. 10/9/15 Csc-111-D01 Hw 3.27

Oct 9th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. /*
  2.  * Omar Natour
  3.  * 10/9/2015
  4.  * Csc-111-D01
  5.  * Problem 3.27
  6.  * Determine whether a point is inside or outside of a predetermined triangle.
  7. */
  8.  
  9. import java.util.Scanner;
  10.  
  11. public class HW4 {
  12.     public static void main(String[] args) {
  13.  
  14.         Scanner input = new Scanner(System.in);
  15.  
  16.         System.out.print("Enter the value of a point (x,y).\nX:");
  17.         double x = input.nextDouble();
  18.         System.out.print("Y:");
  19.         double y = input.nextDouble();
  20.         input.close();
  21.  
  22.         if (x >= 0 && y >= 0) {
  23.             double pos = 200 * (y - 100) - x * -100;
  24.             if (x == 0 || y == 0 || pos == 0)
  25.                 System.out.print("The point (" + x + ", " + y + ") is on the line of the triangle.");
  26.             else if (pos < 0)
  27.                 System.out.print("The point (" + x + ", " + y + ") is in the triangle.");
  28.             else
  29.                 System.out.print("The point (" + x + ", " + y + ") is not in the triangle.");
  30.         } else
  31.             System.out.print("The point (" + x + ", " + y + ") is not in the triangle.");
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment