Thursday 26 March 2020

FINDING COORDINATE USING JAVA LANGUAGE

Q-32- Write a java program that takes the x – y coordinates of a point in the Cartesian plane and prints a message telling either an axis on which the point lies or the quadrant in which it is found.

INPUT :
import java.util.Scanner;
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner (System.in);
double x, y;
System.out.println("Enter The Value Of x and y :");
x=sc.nextDouble();
y=sc.nextDouble();
if(x==0 && y==0)
{
System.out.println("("+x+", "+y+") is on the Origin.");
}
else if(x==0 && y>0)
{
System.out.println("("+x+" , "+y+") is on the Y-axis.");
}
else if(x>0 && y==0)
{
System.out.println("("+x+" , "+y+") is on the X-axis.");
}
else if(x==0 && y<0)
{
System.out.println("("+x+" , "+y+") is on the Y-axis.");
}
else if(x<0 && y==0)
{
System.out.println("("+x+" , "+y+") is on the X-axis.");
}
else if(x>0 && y>0)
{
System.out.println("("+x+", "+y+") is on the First Quadrant.");
}
else if(x<0 && y>0)
{
System.out.println("("+x+" , "+y+") is on the Second Quadrant.");
}
else if(x<0 && y<0)
{
System.out.println("("+x+" , "+y+") is on the Third Quadrant.");
}
else if(x>0 && y<0)
{
System.out.println("("+x+" , "+y+") is on the Fourth Quadrant.");
}

}


}

OUTPUT :
Enter The Value Of x and y :
-1 -2.5

(-1.0 , -2.5) is on the Third Quadrant.

Enter The Value Of x and y :
0
4.8
(0.0 , 4.8) is on the Y-axis.


No comments:

Post a Comment