Given below the sample code :
1 public class Section611 {
2 public static void main(String[] args) {
3 convert("illlegal");
4 }
5 public static void convert(String s) {
6 try {
7 float f = Float.parseFloat(s);
8 } catch (NumberFormatException ne) {
9 f = 0;
10 } finally {
11 System.out.println(f);
12 }
13 }
14 }
Find the output after execution of the above code ?
1. 0.0
2. Compilation fails
3. illegal
4. It 'throws' number format exception.
(2)
Compilation fails because the variable at line 9 doesn't have any type because the variable ' f ' at line 7 has it's scope within 'try' block.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.