Advertisement
Omar_Natour

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

Oct 9th, 2015
174
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.  * ojnatour0001@student.stcc.edu
  8. */
  9.  
  10. import java.util.Scanner;
  11.  
  12. public class HW4 {
  13.     public static void main(String[] args) {
  14.  
  15.         Scanner input = new Scanner(System.in);
  16.  
  17.         System.out.print("Enter the value of a point (x,y).\nX:");
  18.         double x = input.nextDouble();
  19.         System.out.print("Y:");
  20.         double y = input.nextDouble();
  21.         input.close();
  22.  
  23.         if (x >= 0 && y >= 0) {
  24.             double pos = 200 * (y - 100) - x * -100;
  25.             if (x == 0 || y == 0 || pos == 0)
  26.                 System.out.print("The point (" + x + ", " + y + ") is on the line of the triangle.");
  27.             else if (pos < 0)
  28.                 System.out.print("The point (" + x + ", " + y + ") is in the triangle.");
  29.             else
  30.                 System.out.print("The point (" + x + ", " + y + ") is not in the triangle.");
  31.         } else
  32.             System.out.print("The point (" + x + ", " + y + ") is not in the triangle.");
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement