Question #27214

7. Write a program that accepts the value of (x, y) x-coordinates and y-coordinates and output its equivalent quadrant, if x = 0, its lies on the x axis, , if y = 0, its lies on the y axis, and if (0,0) origin.

Expert's answer

import java.util.Scanner;public class Test {

publicstatic void main(String[] args) {

Scanners = new Scanner(System.in);

System.out.println("enterx:");

intx = s.nextInt();

System.out.println("entery:");

inty = s.nextInt();

System.out.println(checkQuadrant(x,y));

}

publicstatic String checkQuadrant(int x, int y) {

Stringres;

if(x == 0 || y == 0) {

if(x == 0 && y == 0) {

res= "Origin";

}else {

res= (x == 0) ? "its lies on the x axis"

:"its lies on the y axis";

}

}else {

if(x > 0) {

res= (y > 0) ? "its lies on 1st quadrant"

:"its lies on 4st quadrant";

}else {

res= (y > 0) ? "its lies on 2st quadrant"

:"its lies on 3st quadrant";

}

}

returnres;

}

}

publicstatic void main(String[] args) {

Scanners = new Scanner(System.in);

System.out.println("enterx:");

intx = s.nextInt();

System.out.println("entery:");

inty = s.nextInt();

System.out.println(checkQuadrant(x,y));

}

publicstatic String checkQuadrant(int x, int y) {

Stringres;

if(x == 0 || y == 0) {

if(x == 0 && y == 0) {

res= "Origin";

}else {

res= (x == 0) ? "its lies on the x axis"

:"its lies on the y axis";

}

}else {

if(x > 0) {

res= (y > 0) ? "its lies on 1st quadrant"

:"its lies on 4st quadrant";

}else {

res= (y > 0) ? "its lies on 2st quadrant"

:"its lies on 3st quadrant";

}

}

returnres;

}

}

## Comments

## Leave a comment