Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static float R;
- public static float getFloat() throws Exception
- {
- byte[] buf = new byte[12];
- System.in.read(buf);
- return new Float(new String(buf, 0, 12));
- }
- public static boolean check(myPoint p) throws Exception
- {
- if (p.x<=0 && p.x>=-R) //in the left part
- {
- 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
- return true;
- } else if (p.x>0 && p.x<=R) //in the right part
- {
- if (p.y>=0 && p.y<=R/2)
- return true;
- }
- return false; //nowhere
- }
- public static void main(String[] args) {
- try {
- myPoint[] A = {new myPoint(4,4), new myPoint(3, -3), new myPoint(-3, 5), new myPoint(-4, 3), new myPoint(-2, -1)};
- System.out.print("Enter R: ");
- R = getFloat();
- for (myPoint p : A)
- if (check(p)) System.out.println(p);
- } catch (Exception e) {
- System.err.println(e.toString());
- }
- }
- }
- class myPoint extends Object
- {
- float x;
- float y;
- public myPoint(float x, float y)
- {
- this.x = x;
- this.y = y;
- }
- public String toString()
- {
- return "X: "+this.x+" Y: "+this.y;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement