解决方案 »

  1.   

    如果要执行里面的else,offsetX要在-5到5之间,而Math.abs(offsetX) > Math.abs(offsetY),所以offsetY不会在-5和5之间。
      

  2.   

    if (Math.abs(offsetX) > Math.abs(offsetY)) {
                            if (offsetX < -5) {
                                System.out.println("left");
                            } else if (offsetX > 5) {
                                System.out.println("right");
                            } 
                            
                            } else {
                                if (offsetY < -5) {
                                    System.out.println("up");
                                } else if (offsetY > 5) {
                                    System.out.println("down");
                                }
                             
                        }
      

  3.   

    if (Math.abs(offsetX) > Math.abs(offsetY)) {
                            if (offsetX < -5) {
                                System.out.println("left");
                            } else if (offsetX > 5) {
                                System.out.println("right");
                            } 
                        } else {
                                if (offsetY < -5) {
                                    System.out.println("up");
                                } else if (offsetY > 5) {
                                    System.out.println("down");
                                }
                            }