- 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
3 Réponses
+ 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));
}
0
Thank you!
0
Thanks for the detailed explanation! Now I understand.