Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Write an expression that checks for given point (x, y)
- * if it is within the circle K({1, 1}, 1.5) and
- * out of the rectangle R(top=1, left=-1, width=6, height=2). */
- import java.util.Locale;
- import java.util.Scanner;
- public class _10_PointInsideACircleButOutsideOfARectangle {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Locale.setDefault(Locale.ROOT);
- Scanner input = new Scanner(System.in);
- System.out.print("Enter value for X-coordinate of your Point: ");
- double pointX = input.nextDouble();
- System.out.print("Enter value for Y-coordinate of your Point: ");
- double pointY = input.nextDouble();
- input.close();
- double circleCenter = 1d;
- double radius = 1.5;
- double pointCircleResult = Math.sqrt(((pointX - circleCenter) * (pointX - circleCenter))
- + ((pointY - circleCenter) * (pointY - circleCenter)));
- boolean pointInsideCircle = pointCircleResult <= radius;
- double leftX = -1, rightX = leftX + 6;
- double topY = 1, downY = topY - 2;
- boolean pointOutsideRectangle = !(pointX >= leftX && pointX <= rightX
- && pointY >= downY && pointY <= topY);
- String result = (pointInsideCircle && pointOutsideRectangle) ? "yes" : "no";
- System.out.printf("That Point is Inside a Circle, but Outside of a Rectangle: %s !\n", result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement