如题所述
Java我不了解,但是算法和c相比应该是基本一样的,就是用if判断横坐标和纵坐标大于0还是小于0,然后输出。
温馨提示:答案为网友推荐,仅供参考
第1个回答 2017-03-23
这题我已前写过。我找找。追问
坐标输入那块我没写,太简单了。
如果你不会写,用baidu搜一下java console 输入,或java scanner,仿照写一下。
public class JudgeQuadrant {
public static void main(String[] args) {
double x = -1.0f;
double y = 2.0f;
double sinA, cosA;
if (x==0.0f && y==0.0f) {
System.out.printf("(%f,%f) 原点\n", x, y);
} else if (x==0.0f) {
System.out.printf("(%f,%f) 在X轴上\n", x, y);
} else if (y==0.0f) {
System.out.printf("(%f,%f) 在y轴上\n", x, y);
} else {
double A = x/y;
sinA = Math.sin(A);
cosA = Math.cos(A);
if (sinA>0 && cosA>0) {
System.out.printf("(%f,%f) 在第1象限\n", x, y);
} else if (sinA>0 && cosA<0) {
System.out.printf("(%f,%f) 在第2象限\n", x, y);
} else if (sinA<0 && cosA<0) {
System.out.printf("(%f,%f) 在第3象限\n", x, y);
} else {
System.out.printf("(%f,%f) 在第4象限\n", x, y);
}
}
}
}追问
public class JudgeQuadrant {
public static void main(String[] args) {
double x = -1.0f;
double y = -20.0f;
if (x==0.0f && y==0.0f) {
System.out.printf("(%f,%f) 原点\n", x, y);
} else if (x==0.0f) {
System.out.printf("(%f,%f) 在X轴上\n", x, y);
} else if (y==0.0f) {
System.out.printf("(%f,%f) 在y轴上\n", x, y);
} else {
if (x>0 && y>0) {
System.out.printf("(%f,%f) 在第1象限\n", x, y);
} else if (x<0 && y>0) {
System.out.printf("(%f,%f) 在第2象限\n", x, y);
} else if (x<0 && y<0) {
System.out.printf("(%f,%f) 在第3象限\n", x, y);
} else {
System.out.printf("(%f,%f) 在第4象限\n", x, y);
}
}
}
}追问
import java.util.Scanner;
public class JudgeQuadrant {
public static void main(String[] args) {
double x;
double y;
Scanner s = new Scanner(System.in);
x = s.nextDouble();
y = s.nextDouble();
s.close();
if (x==0.0f && y==0.0f) {
System.out.printf("(%f,%f) 原点\n", x, y);
} else if (x==0.0f) {
System.out.printf("(%f,%f) 在X轴上\n", x, y);
} else if (y==0.0f) {
System.out.printf("(%f,%f) 在y轴上\n", x, y);
} else {
if (x>0 && y>0) {
System.out.printf("(%f,%f) 在第1象限\n", x, y);
} else if (x<0 && y>0) {
System.out.printf("(%f,%f) 在第2象限\n", x, y);
} else if (x<0 && y<0) {
System.out.printf("(%f,%f) 在第3象限\n", x, y);
} else {
System.out.printf("(%f,%f) 在第4象限\n", x, y);
}
}
}
}追问
但前一种写法在这种情况比较简便。追问
好的
追答没找着,重新写了一个。坐标输入那块我没写,太简单了。
如果你不会写,用baidu搜一下java console 输入,或java scanner,仿照写一下。
public class JudgeQuadrant {
public static void main(String[] args) {
double x = -1.0f;
double y = 2.0f;
double sinA, cosA;
if (x==0.0f && y==0.0f) {
System.out.printf("(%f,%f) 原点\n", x, y);
} else if (x==0.0f) {
System.out.printf("(%f,%f) 在X轴上\n", x, y);
} else if (y==0.0f) {
System.out.printf("(%f,%f) 在y轴上\n", x, y);
} else {
double A = x/y;
sinA = Math.sin(A);
cosA = Math.cos(A);
if (sinA>0 && cosA>0) {
System.out.printf("(%f,%f) 在第1象限\n", x, y);
} else if (sinA>0 && cosA<0) {
System.out.printf("(%f,%f) 在第2象限\n", x, y);
} else if (sinA<0 && cosA<0) {
System.out.printf("(%f,%f) 在第3象限\n", x, y);
} else {
System.out.printf("(%f,%f) 在第4象限\n", x, y);
}
}
}
}追问
虽然有点看不懂(T▽T)谢谢~我慢慢理解下吧
追答等会,做错了,待我想一下。
追问嗯
追答这回是对的了。刚才画蛇添足了。public class JudgeQuadrant {
public static void main(String[] args) {
double x = -1.0f;
double y = -20.0f;
if (x==0.0f && y==0.0f) {
System.out.printf("(%f,%f) 原点\n", x, y);
} else if (x==0.0f) {
System.out.printf("(%f,%f) 在X轴上\n", x, y);
} else if (y==0.0f) {
System.out.printf("(%f,%f) 在y轴上\n", x, y);
} else {
if (x>0 && y>0) {
System.out.printf("(%f,%f) 在第1象限\n", x, y);
} else if (x<0 && y>0) {
System.out.printf("(%f,%f) 在第2象限\n", x, y);
} else if (x<0 && y<0) {
System.out.printf("(%f,%f) 在第3象限\n", x, y);
} else {
System.out.printf("(%f,%f) 在第4象限\n", x, y);
}
}
}
}追问
(*^▽^*) 嗯嗯~万分感谢
追答完整的。import java.util.Scanner;
public class JudgeQuadrant {
public static void main(String[] args) {
double x;
double y;
Scanner s = new Scanner(System.in);
x = s.nextDouble();
y = s.nextDouble();
s.close();
if (x==0.0f && y==0.0f) {
System.out.printf("(%f,%f) 原点\n", x, y);
} else if (x==0.0f) {
System.out.printf("(%f,%f) 在X轴上\n", x, y);
} else if (y==0.0f) {
System.out.printf("(%f,%f) 在y轴上\n", x, y);
} else {
if (x>0 && y>0) {
System.out.printf("(%f,%f) 在第1象限\n", x, y);
} else if (x<0 && y>0) {
System.out.printf("(%f,%f) 在第2象限\n", x, y);
} else if (x<0 && y<0) {
System.out.printf("(%f,%f) 在第3象限\n", x, y);
} else {
System.out.printf("(%f,%f) 在第4象限\n", x, y);
}
}
}
}追问
请问下输出里面的(%f.%f)是什么意思呢
追答就是输出浮点数,这是C语言的写法。
也可以这样写:
System.out.println("(" + x + "," + y + ") 在第4象限");但前一种写法在这种情况比较简便。追问
哦哦~😶知道啦
本回答被提问者采纳