Answer to Question #27214 in Java | JSP | JSF for MARK KEVIN

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.
1
Expert's answer
2013-03-29T05:24:11-0400
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;
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS