Write code to Parse string to Int with default value
//package com.book2s; public class Main { public static void main(String[] argv) { String source = "book2s.com"; int def = 42; System.out.println(ParseInt(source, def)); }/* w w w .java2s . c o m*/ public static int ParseInt(String source, int def) { try { return Integer.parseInt(source); } catch (NumberFormatException e) { return def; } } }