Problem:
Write a program that prompts the user to input the x-y coordinate of a point in a Cartesian plane. The program should then output a message indicating whether the point is the origin point, is located on the x or y axis or appears on a particular quadrant.Sample Output:
package javaapplication1; import java.io.*; public class N8 { public static BufferedReader q=new BufferedReader (new InputStreamReader (System.in)); public static void main (String []args)throws IOException{ System.out.print("Input x: "); String X=q.readLine(); int x=Integer.parseInt(X); System.out.print("Input y: "); String Y=q.readLine(); int y=Integer.parseInt(Y); if (x>0 && y>0) { System.out.print("Quadrant 1"); } else if (x<0 && y>0) { System.out.print("Quadrant 2"); } else if (x<0 && y<0) { System.out.print("Quadrant 3"); } else if (x>0 && y<0) { System.out.print("Quadrant 4"); } else if (x==0 && y<0) { System.out.print("Y axis"); } else if (x==0 && y<0 && y>0) { System.out.print("Y axis"); } else if (x<0 && y==0) { System.out.print("X axis"); } else if (x>0 && y==0) { System.out.print("X axis"); } else { System.out.print("Origin"); } } } |
0 comments:
Post a Comment