Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Write an expression that checks if given point (x, y) is inside a circle K({0, 0}, 2).
- import java.util.Locale;
- import java.util.Scanner;
- public class CheckGivenPointIsInsideACircle {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Locale.setDefault(Locale.ROOT);
- double radius = 2.0;
- System.out.print("Enter X-coordinate of your point: ");
- Scanner input = new Scanner(System.in);
- double pointX = input.nextDouble();
- System.out.print("Enter Y-coordinate of your point: ");
- double pointY = input.nextDouble();
- input.close();
- double pointResult = Math.sqrt((pointX * pointX) + (pointY * pointY));
- boolean pointIsInside = pointResult <= radius;
- System.out.printf(
- "The Point(%1$.3f, %2$.3f) is Inside a Circle: %3$b !\n",
- pointX, pointY, pointIsInside);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement