Advertisement
dimipan80

Point in a Circle

Aug 4th, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. // Write an expression that checks if given point (x,  y) is inside a circle K({0, 0}, 2).
  2.  
  3. import java.util.Locale;
  4. import java.util.Scanner;
  5.  
  6. public class CheckGivenPointIsInsideACircle {
  7.  
  8.     public static void main(String[] args) {
  9.         // TODO Auto-generated method stub
  10.         Locale.setDefault(Locale.ROOT);
  11.         double radius = 2.0;
  12.         System.out.print("Enter X-coordinate of your point: ");
  13.         Scanner input = new Scanner(System.in);
  14.         double pointX = input.nextDouble();
  15.         System.out.print("Enter Y-coordinate of your point: ");
  16.         double pointY = input.nextDouble();
  17.         input.close();
  18.  
  19.         double pointResult = Math.sqrt((pointX * pointX) + (pointY * pointY));
  20.         boolean pointIsInside = pointResult <= radius;
  21.  
  22.         System.out.printf(
  23.                 "The Point(%1$.3f, %2$.3f) is Inside a Circle: %3$b !\n",
  24.                 pointX, pointY, pointIsInside);
  25.     }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement