Java 7,130字节
String c(int x,int y){return x==0&y==0?"That goes nowhere, silly!":"North xxSouth ".split("x")[y+1]+"WestxxEast".split("x")[x+1];}
说明:
String c(int x, int y){ // Method with x and y integer parameters and String return-type
return x==0&y==0 ? // If both x and y are 0:
"That goes nowhere, silly!" // Return "That goes nowhere, silly!"
: // Else:
"North xxSouth ".split("x"[y+1] // Get index y+1 from array ["North ","","South "] (0-indexed)
+ "WestxxEast".split("x")[x+1]; // Plus index x+1 from array ["West","","East"] (0-indexed)
} // End of method
测试代码:
在这里尝试。
class M{
static String c(int x,int y){return x==0&y==0?"That goes nowhere, silly!":"North xxSouth ".split("x")[y+1]+"WestxxEast".split("x")[x+1];}
public static void main(String[] a){
System.out.println(c(1, 1));
System.out.println(c(0, 1));
System.out.println(c(1, -1));
System.out.println(c(0, 0));
}
}
输出:
South East
South
North East
That goes nowhere, silly!