ReverseInteger { public int reverse(int x) { if (x < 10 && x > -10) return x; long y = x; long i = 1; while ((y = y / 10) != 0) { i = i * 10; } y = 0; long xy = x; long j = 1; while (i > 0) { long q = xy / i; y = y + q * j; xy %= i; i = i / 10; j *= 10; } return (y > Integer.MAX_VALUE || y < Integer.MIN_VALUE) ? 0 : (int)y; }  int reverse(int x);  }
@Test(dataProvider = "reverseNumbers") public void testReverseNumber(int number, int expected) { assertEquals(new ReverseInteger().reverse(number), expected); }