- 1

Why double and not int

str. length() = 2; 2 is less than three, it means int and not a double. https://code.sololearn.com/c3wcW9ca0tpc/?ref=app

19th Mar 2021, 11:24 AM
Alesh Boldrew
Alesh Boldrew - avatar
5 Respuestas
+ 2
it sounds like java use double as ternary return value if both parts are numbers but one is double and other is int... you must write it with plain if...else statement rather than using ternary operator: if (str.length() > 3) { System.out.println(Double.parseDouble(str)); } else { System.out.println(Integer.parseInt(str)); }
19th Mar 2021, 11:54 AM
visph
visph - avatar
0
Thank you!
19th Mar 2021, 12:14 PM
Alesh Boldrew
Alesh Boldrew - avatar
0
Thanks for the detailed explanation! Now I understand.
19th Mar 2021, 1:27 PM
Alesh Boldrew
Alesh Boldrew - avatar