Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. public class Main {
  2.  
  3.     public static float R;
  4.  
  5.     public static float getFloat() throws Exception
  6.     {
  7.         byte[] buf = new byte[12];
  8.         System.in.read(buf);
  9.         return new Float(new String(buf, 0, 12));
  10.     }
  11.  
  12.     public static boolean check(myPoint p) throws Exception
  13.     {
  14.         if (p.x<=0 && p.x>=-R) //in the left part
  15.         {
  16.             if (p.y>=0 && Math.sqrt(p.x*p.x+p.y*p.y)<=R || p.y<0 && p.y>=-p.x-R) //in circle part
  17.                 return true;
  18.         } else if (p.x>0 && p.x<=R) //in the right part
  19.         {
  20.             if (p.y>=0 && p.y<=R/2)
  21.                 return true;
  22.         }
  23.         return false; //nowhere
  24.     }
  25.  
  26.     public static void main(String[] args) {
  27.         try {
  28.             myPoint[] A = {new myPoint(4,4), new myPoint(3, -3), new myPoint(-3, 5), new myPoint(-4, 3), new myPoint(-2, -1)};
  29.             System.out.print("Enter R: ");
  30.             R = getFloat();
  31.             for (myPoint p : A)
  32.                 if (check(p)) System.out.println(p);
  33.         } catch (Exception e) {
  34.             System.err.println(e.toString());
  35.         }
  36.     }
  37. }
  38.  
  39. class myPoint extends Object
  40. {
  41.     float x;
  42.     float y;
  43.     public myPoint(float x, float y)
  44.     {
  45.         this.x = x;
  46.         this.y = y;
  47.     }
  48.     public String toString()
  49.     {
  50.         return "X: "+this.x+" Y: "+this.y;
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement