The quadrant in which line drawn from the origin resides
is determined by the angle that the line makes with the
positive x axis as follows:
Using this information, write a Java method that accepts the
angle of the line as user input and determines and displays
the quadrant appropriate to the input data. (Note: if the
angle is exactly 0, 90, 180, or 270 degrees the corresponding
line does not reside in any quadrant but lies on an axis).
Note: Use if Control statement
import java.io.*;
import java.util.Scanner;
class Main{
static void qua(int angle, int angle2)
{
if (angle >0 && angle2 > 0)
System.out.println("lies in First quadrant");
else if (angle < 0 && angle2 > 0)
System.out.println("lies in Second quadrant");
else if (angle < 0 && angle2 < 0)
System.out.println("lies in Third quadrant");
else if (angle > 0 && angle2 < 0)
System.out.println("lies in Fourth quadrant");
else if (angle == 0 && angle2 > 0)
System.out.println("lies at positive y axis");
else if (angle == 0 && angle2 < 0)
System.out.println("lies at negative y axis");
else if (angle2 == 0 && angle < 0)
System.out.println("lies at negative x axis");
else if (angle2 == 0 && angle > 0)
System.out.println("lies at positive x axis");
else
System.out.println("lies at origin");
}
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
int angle = input.nextInt();
int angle2 = input.nextInt();
qua(angle, angle2);
}
}
Comments
Leave a comment