Go to Top

Thursday, 20 October 2011

Utilities 17 : Reflection

This will help you to find the reflected point in x-axis, y-axis, or origin.

Java Program :

import java.io.*;
class reflection
{
 static int x,y;
 static char m;
 static void main()throws IOException
 {
     input();
     cal();
    }
    static void input()throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.print("A = (x,y)");
        System.out.print("\n\nx = ");
        x=Integer.parseInt(br.readLine());
        System.out.print("\ny = ");
        y=Integer.parseInt(br.readLine());
        System.out.print("\nReflection axis (x,y,o) : ");
        m=(char)br.read();
    }
    static void cal()
    {
        int c=0;
        if(m=='y' || m=='Y')
        x*=-1;
        else if(m=='x' || m=='X')
        y*=-1;
        else if(m=='o' || m=='O')
        {
            x*=-1;
            y*=-1;
        }
        else
        {
            System.out.print("\nInvalid input\n");
            c++;
        }
        if(c==0)
        display();
    }
    static void display()
    {
        System.out.print("\nThe reflected point A' = ("+x+","+y+")");
    }
}

No comments:

Post a Comment

ShareThis