What will the following code snippet print:
public class Main { public static void main(String[] args) throws Exception { Float f = null;/*from w ww .j a v a 2s.co m*/ try { f = Float.valueOf("12.3"); String s = f.toString(); int i = Integer.parseInt(s); System.out.println("i = " + i); } catch (Exception e) { System.out.println("trouble : " + f); } } }
Select 1 option
Correct Option is : D
f = Float.valueOf ("12.3"); executes without any problem.
int i = Integer.parseInt (s); throws a NumberFormatException because 12.3 is not an integer.
The catch block prints trouble : 12.3