0

Explain that

why is the answer RUNTIME EXCEPTION? int value = Integer.parse("12.7");

25th Apr 2018, 1:21 PM
Aleksandr Efremov
Aleksandr Efremov - avatar
6 Respuestas
+ 1
If you want to parse an integer, you should use .parseInt method , moreover, in this case the string must be “12”, not “12.7” For example: int value = Integer.parseInt("12");
25th Apr 2018, 2:01 PM
Lev
Lev - avatar
+ 1
12.7 is a double/float not an int
25th Apr 2018, 3:17 PM
TurtleShell
TurtleShell - avatar
+ 1
Thats fine but if you try Integer.parse("12.7"); it will cause an error
25th Apr 2018, 3:37 PM
TurtleShell
TurtleShell - avatar
0
Are you sure that I can't use 12.7 as a String???
25th Apr 2018, 2:34 PM
Aleksandr Efremov
Aleksandr Efremov - avatar
0
I mean String string = "12.7";
25th Apr 2018, 3:35 PM
Aleksandr Efremov
Aleksandr Efremov - avatar
0
Got it, thanks!
25th Apr 2018, 3:43 PM
Aleksandr Efremov
Aleksandr Efremov - avatar