Numbers { public static int pow(int x, int y) { if (x == 1 || y == 0) return 1; else if (y == 1) return x; else if (y == 2) return x * x; else if (y == 3) return x * x * x; final int sqrt = pow(x, y / 2); if (y % 2 == 0) return sqrt * sqrt; else return x * sqrt * sqrt; }  static boolean isReal(double value); static int pow(int x, int y); static double parseDouble(@Nullable String str); @Nullable static Double parseDoubleNull(@Nullable String str); static float parseFloat(@Nullable String str); static int parseInt(@Nullable String str, int defaultValue); static final DecimalFormat format2; static final DecimalFormat format3; static final DecimalFormat format6; }
@Test public void pow() { assertEquals(0, Numbers.pow(0, 1)); assertEquals(0, Numbers.pow(0, 2)); assertEquals(1, Numbers.pow(1, 0)); assertEquals(1, Numbers.pow(1, 1)); assertEquals(1, Numbers.pow(1, 2)); assertEquals(1, Numbers.pow(2, 0)); assertEquals(2, Numbers.pow(2, 1)); assertEquals(4, Numbers.pow(2, 2)); assertEquals(8, Numbers.pow(2, 3)); assertEquals(16, Numbers.pow(2, 4)); assertEquals(32, Numbers.pow(2, 5)); assertEquals(256, Numbers.pow(2, 8)); assertEquals(65536, Numbers.pow(2, 16)); assertEquals(1, Numbers.pow(10, 0)); assertEquals(10, Numbers.pow(10, 1)); assertEquals(100, Numbers.pow(10, 2)); assertEquals(1, Numbers.pow(-1, 0)); assertEquals(-1, Numbers.pow(-1, 1)); assertEquals(1, Numbers.pow(-1, 2)); assertEquals(1, Numbers.pow(-2, 0)); assertEquals(-2, Numbers.pow(-2, 1)); assertEquals(4, Numbers.pow(-2, 2)); }