Design a Java application that prompts the user to input the

Design a Java application that prompts the user to input the x- and y-coordinates of a point in a Cartesian plane. The program then should output a message indicating whether the point is the origin, or is located on the x (or y) axis, or appears in a particular quadrant. For example: (0, 0) is the origin (4, 0) is on the x-axis (0, -3) is on the y-axis (-2, 3) is in the second quadrant The numbering of the quadrants is as follows:

Solution

import java.util.Scanner;
public class Ex1_1{

public static void main(String []args){
Scanner sc=new Scanner(System.in);   
System.out.println(\"Enter the coordinates in cartesian plane\"); //asking for the input from the user
int x=sc.nextInt(); //storing the x-axis value in x
int y=sc.nextInt(); //storing the y-axis value in x
if((x==0 && y!=0)||(y==0 && x!=0)) // condition for determing whether the point is in either x-axis or y-axis
{
if(x==0)
System.out.println(\"(\"+x+\",\"+y+\")\"+\" is on the y-axis\");
else
System.out.println(\"(\"+x+\",\"+y+\")\"+\" is on the x-axis\");


}
else if(x==0&&y==0)
System.out.println(\"(\"+x+\",\"+y+\")\"+\" is the origin\");               // condition for determing whether the point is the origin   

else
{
if(x>0 && y>0)
System.out.println(\"(\"+x+\",\"+y+\")\"+\" is in the first quadrant \");   // condition for determing whether the point is in the first quadrant
else if(x<0 && y>0)
System.out.println(\"(\"+x+\",\"+y+\")\"+\" is in the second quadrant \");   // condition for determing whether the point is in the second quadrant
else if(x<0 && y<0)
System.out.println(\"(\"+x+\",\"+y+\")\"+\" is in the third quadrant \"); // condition for determing whether the point is in the third quadrant
else
System.out.println(\"(\"+x+\",\"+y+\")\"+\" is in the fourth quadrant \"); // condition for determing whether the point is in the fourth quadrant
  
}


}
}


/********************output begins *********************/
Enter the coordinates in cartesian plane
0   
0   
(0,0) is the origin
Enter the coordinates in cartesian plane
4   
0   
(4,0) is on the x-axis
Enter the coordinates in cartesian plane
0   
-3
(0,-3) is on the y-axis
Enter the coordinates in cartesian plane
-2
3   
(-2,3) is in the second quadrant

/********************output ends *********************/
Please let me know in case you have any doubts.

 Design a Java application that prompts the user to input the x- and y-coordinates of a point in a Cartesian plane. The program then should output a message ind
 Design a Java application that prompts the user to input the x- and y-coordinates of a point in a Cartesian plane. The program then should output a message ind

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site