@Test public void testStringToInt() { try { stringToInt(null); Assert.fail(); } catch (NumberFormatException iae) { } try { stringToInt("123abc"); Assert.fail(); } catch (NumberFormatException iae) { } int result = stringToInt("-123"); Assert.assertEquals(-123, result); result = stringToInt("123"); Assert.assertEquals(123, result); }
public static int stringToInt(String s) { final String regex = "^-?\\d+"; if (s == null || !s.matches(regex)) { throw new NumberFormatException(s + " is not a valid integer encoding."); } return parseInt(s, 10, s.length() - 1); }
PracticeQuestionsCh5 { public static int stringToInt(String s) { final String regex = "^-?\\d+"; if (s == null || !s.matches(regex)) { throw new NumberFormatException(s + " is not a valid integer encoding."); } return parseInt(s, 10, s.length() - 1); } }
PracticeQuestionsCh5 { public static int stringToInt(String s) { final String regex = "^-?\\d+"; if (s == null || !s.matches(regex)) { throw new NumberFormatException(s + " is not a valid integer encoding."); } return parseInt(s, 10, s.length() - 1); }  }
PracticeQuestionsCh5 { public static int stringToInt(String s) { final String regex = "^-?\\d+"; if (s == null || !s.matches(regex)) { throw new NumberFormatException(s + " is not a valid integer encoding."); } return parseInt(s, 10, s.length() - 1); }  static long[] computeParities(final long[] input); static long swapBits(final long x, final int i, final int j); static void powerSet(Set<Integer> set); static int stringToInt(String s); static String changeBase(String s, int b1, int b2); }
PracticeQuestionsCh5 { public static int stringToInt(String s) { final String regex = "^-?\\d+"; if (s == null || !s.matches(regex)) { throw new NumberFormatException(s + " is not a valid integer encoding."); } return parseInt(s, 10, s.length() - 1); }  static long[] computeParities(final long[] input); static long swapBits(final long x, final int i, final int j); static void powerSet(Set<Integer> set); static int stringToInt(String s); static String changeBase(String s, int b1, int b2); static final Logger LOGGER; }