Advertisement
dimipan80

Point Inside a Circle & Outside of a Rectangle

Aug 5th, 2014
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1. /* Write an expression that checks for given point (x, y)
  2.  * if it is within the circle K({1, 1}, 1.5) and
  3.  * out of the rectangle R(top=1, left=-1, width=6, height=2). */
  4.  
  5. import java.util.Locale;
  6. import java.util.Scanner;
  7.  
  8. public class _10_PointInsideACircleButOutsideOfARectangle {
  9.  
  10.     public static void main(String[] args) {
  11.         // TODO Auto-generated method stub
  12.         Locale.setDefault(Locale.ROOT);
  13.         Scanner input = new Scanner(System.in);
  14.         System.out.print("Enter value for X-coordinate of your Point: ");
  15.         double pointX = input.nextDouble();
  16.         System.out.print("Enter value for Y-coordinate of your Point: ");
  17.         double pointY = input.nextDouble();
  18.         input.close();
  19.  
  20.         double circleCenter = 1d;
  21.         double radius = 1.5;
  22.         double pointCircleResult = Math.sqrt(((pointX - circleCenter) * (pointX - circleCenter))
  23.                         + ((pointY - circleCenter) * (pointY - circleCenter)));
  24.         boolean pointInsideCircle = pointCircleResult <= radius;
  25.  
  26.         double leftX = -1, rightX = leftX + 6;
  27.         double topY = 1, downY = topY - 2;
  28.         boolean pointOutsideRectangle = !(pointX >= leftX && pointX <= rightX
  29.                 && pointY >= downY && pointY <= topY);
  30.  
  31.         String result = (pointInsideCircle && pointOutsideRectangle) ? "yes" : "no";
  32.         System.out.printf("That Point is Inside a Circle, but Outside of a Rectangle: %s !\n", result);
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement