+ 5

Why this question output false.

I got this today😑 https://drive.google.com/file/d/0B1nEuUWCfjliN1g5WFZFTkQ2OEU/view?usp=drivesdk I don't understand this please explain?😓😓😢😢😢

12th Aug 2017, 3:31 AM
Nithiwat
Nithiwat - avatar
7 Respuestas
+ 10
Erm OK lol didn't see that. The dot shouldn't be there. It should be a[i] and b[i] afaic, probably a silly mistake made by quiz creator. Have you reported it to SL? EDIT: Strings don't work directly with array indexes. Refer @Nithiwat's reply.
12th Aug 2017, 4:09 AM
Hatsy Rei
Hatsy Rei - avatar
+ 10
Why did it get through preliminary submissions in the first place :blobfacepalm:
12th Aug 2017, 4:27 AM
Hatsy Rei
Hatsy Rei - avatar
+ 9
In Java, == and != checks if the string object refers to the same object or not, instead of comparing the string content. In the quiz provided, the two objects will always be different instances, hence it will always return false. https://stackoverflow.com/questions/8484668/java-does-not-equal-not-working
12th Aug 2017, 3:54 AM
Hatsy Rei
Hatsy Rei - avatar
+ 7
@Hatsy it also doesn't work😣😣 https://code.sololearn.com/c1tN9NsvWRe2/?ref=app it makes error😑😑 /*java not support to using String instead array you can use charAt() instead*/
12th Aug 2017, 4:19 AM
Nithiwat
Nithiwat - avatar
+ 6
@Hatsy I already test in code playground but it got errors. cause of a.[i] and b.[i] I don't understand why error please help😣😣
12th Aug 2017, 4:07 AM
Nithiwat
Nithiwat - avatar
+ 3
Java does not support the use of array subscripts for strings. As the error says, use charAt(). Like so: if(a.charAt(i) != b.charAt(i)) So the question is incorrect due to syntax related reasons, however, the logic is fine. Although, you also made another mistake in the code you wrote: The line "return true", is inside the for loop. It should be outside of the loop, at the end of the method.
12th Aug 2017, 5:07 AM
Rrestoring faith
Rrestoring faith - avatar
+ 2
It sounds like it's the same issue with a question in java with cout... Someone (can't open [a link to] the screenshot, like it's not available already) tries to transfer question from one language to another and don't put enough effort to check them... and, Yes, I am interested too in "how it gets trough?!?"
12th Aug 2017, 5:36 AM
Andrew Harchenko (Tomsk)
Andrew Harchenko (Tomsk) - avatar