daily pastebin goal
70%
SHARE
TWEET

CSC-111 Point In Triangle Homework

a guest Oct 13th, 2016 149 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. // Antonio C. Silvestri
  2. // 10/13/2016
  3. // Point in Triangle Homework
  4.  
  5. import java.util.*;
  6.  
  7. public class PointInTriangle {
  8.  
  9.     public static void main(String[] args) {
  10.         Scanner input = new Scanner(System.in);
  11.         System.out.print("Enter y intercept: ");
  12.         double yint = input.nextDouble();
  13.         System.out.print("Enter x intercept: ");
  14.         double xint = input.nextDouble();
  15.  
  16.         if (yint <= 0 || xint <= 0)
  17.             System.out.println("Please enter only positive intercepts.");
  18.         else {
  19.             System.out.print("Enter point (x,y): ");
  20.             double x = input.nextDouble();
  21.             double y = input.nextDouble();
  22.  
  23.             boolean pointInTriangle;
  24.             if (x < 0 || x > xint)
  25.                 pointInTriangle = false;
  26.             else if (y < 0)
  27.                 pointInTriangle = false;
  28.             else {
  29.                 double yTriangle = (-yint / xint) * x + yint;
  30.                 if (y < yTriangle)
  31.                     pointInTriangle = true;
  32.                 else
  33.                     pointInTriangle = false;
  34.             }
  35.  
  36.             if (pointInTriangle)
  37.                 System.out.println("Point In Triangle");
  38.             else
  39.                 System.out.println("Point NOT In Triangle");
  40.         }
  41.         input.close();
  42.     }
  43.  
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top