We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
That's because in the above code, in.substring(0,2)=="12" and in.substring(0,2)!="12" always return "same result" irrespective of the content in "in". Operators '==' and '!=' work on object identity, which means, even if the two strings have the same value, they are still two different objects and hence would always be considered unequal.
This can be corrected in two different ways :
1) Use in.substring(0,2).intern() in place of in.substring(0,2).
2) Use .equals() in place of ==.
Moreover, replace out[0] = 0; out[1] = 0; by out[0] = '0'; out[1] = '0';, otherwise it will still give wrong result (char, not int).
Time Conversion
You are viewing a single comment's thread. Return to all comments →
That's because in the above code,
in.substring(0,2)=="12"
andin.substring(0,2)!="12"
always return "same result" irrespective of the content in "in". Operators '==
' and '!=
' work on object identity, which means, even if the two strings have the same value, they are still two different objects and hence would always be considered unequal.This can be corrected in two different ways :
1) Use
in.substring(0,2).intern()
in place ofin.substring(0,2)
.2) Use
.equals()
in place of==
.Moreover, replace
out[0] = 0; out[1] = 0;
byout[0] = '0'; out[1] = '0';
, otherwise it will still give wrong result (char, not int).In short, the final conditions should become :
Let me know if you still face any issue !