public class Main { public static void main(String[] args) { try { int n = Integer.parseInt("42"); // TODO: print n } catch (NumberFormatException e) { System.out.println("Invalid"); } try { Integer.parseInt("not a number"); } catch (NumberFormatException e) { // TODO: print "Invalid" } } }
Output
Click Run to execute, or Check to validate.
Ask questions or share tips about this tutorial
Sign in to join the discussion