- import java.util.Scanner;
- public class JPA01 {
- static Scanner keyboard = new Scanner(System.in);
- public static void main(String[] args) {
- test();
- test();
- test();
- test();
- }
-
- public static void test() {
- System.out.print("請輸入x座標:");
- float x=keyboard.nextFloat();
- System.out.print("請輸入y座標:");
- float y=keyboard.nextFloat();
- if(x>0)
- {
- if(y>0)
- {
- System.out.printf("(%.2f,%.2f)在第一象限\n",x,y);
- }
- else if(y<0)
- {
- System.out.printf("(%.2f,%.2f)在第四象限\n",x,y);
- }
- else
- {
- System.out.printf("(%.2f,%.2f)在x軸上\n",x,y);
- }
- }
- else if(x<0)
- {
- if(y>0)
- {
- System.out.printf("(%.2f,%.2f)在第二象限\n",x,y);
- }
- else if(y<0)
- {
- System.out.printf("(%.2f,%.2f)在第三象限\n",x,y);
- }
- else
- {
- System.out.printf("(%.2f,%.2f)在x軸上\n",x,y);
- }
- }
- else
- {
- if(y==0)
- {
- System.out.printf("(%.2f,%.2f)在原點上\n",x,y);
- }
- else
- {
- System.out.printf("(%.2f,%.2f)在y軸上\n",x,y);
- }
- }
- }
- }
複製代碼 |