[UPDATE: NO IT'S NOT A wrong answer (was "wrong answer" first)] Challenge in Java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8

[UPDATE: NO IT'S NOT A wrong answer (was "wrong answer" first)] Challenge in Java

What is the output? public class Main { public static void main(String[] args){ int sum=0, bum=0; for(int i=1;i<=5;++i) sum+=i; for([deleted] i=1;i<=5;i++) bum+=i; if(sum==bum) System.out.print("1"); else System.out.print("0"); } } I gave the answer "1". And it was wrong (right answer:error)! Another fellow sololearner found out there really was an error (see comments). Typed code in playgrounds, so you can see it yourself: https://code.sololearn.com/ctCgXzNI2oR5/?ref=app

25th Apr 2017, 7:33 PM
Andrew Harchenko (Tomsk)
Andrew Harchenko (Tomsk) - avatar
21 Answers
+ 11
Playground code does not match. Again look at the 2nd for loop in the question, it does not have "int" written before the i. It cannot use the i from the first for loop. edit: I agree I don't like that question either. 😛
25th Apr 2017, 7:56 PM
Rrestoring faith
Rrestoring faith - avatar
+ 13
Notice the int declaration is missing on the 2nd for loop. This is an error, the code is correct. its: "for(i=1...)" not: for(int i = 1)..."
25th Apr 2017, 7:50 PM
Rrestoring faith
Rrestoring faith - avatar
+ 10
Pls report the question.
25th Apr 2017, 7:38 PM
Tashi N
Tashi N - avatar
+ 10
Thx, Andrew. You've done a good job ^^
25th Apr 2017, 7:41 PM
Tashi N
Tashi N - avatar
+ 10
ehhhh I think they'll ignore the report when they find out the question is right, I'm sure they get lots of reports like that.
25th Apr 2017, 8:12 PM
Rrestoring faith
Rrestoring faith - avatar
+ 10
lol, well I think a missing semi-colon is as close to reality as you get. 😛. Maybe the boss is asking if you've finished it, and the question is 1000 lines of code long. Find the missing semi-colon. As real as it gets😅
25th Apr 2017, 8:23 PM
Rrestoring faith
Rrestoring faith - avatar
+ 9
Yup you're right. Report the question. Make sure you wrote the question correctly too. There could have been something small you missed to cause the error.
25th Apr 2017, 7:39 PM
Rrestoring faith
Rrestoring faith - avatar
+ 9
@Andrew I guess reporting is enough :D If you suggest mods do have the power to edit anything in here - well, we don't.
25th Apr 2017, 7:46 PM
Tashi N
Tashi N - avatar
+ 7
Yep! I was wrong! (I think it's a bad question... but ok) That's why it was right decision to post it here (and it was wrong decision to report it before discussion and review, my fault). To discuss, review and recheck! And to find out where I was wrong. :-/
25th Apr 2017, 7:56 PM
Andrew Harchenko (Tomsk)
Andrew Harchenko (Tomsk) - avatar
+ 7
Math and for loops 😊 you guys get aawwll the fun!
25th Apr 2017, 8:10 PM
Leon
Leon - avatar
+ 5
@Rrestoring faith Thank you! I've edited the answer, the question and some comments (and code too) to notice every one reading it that I was wrong! What an Eagle eye you are! ;-) (And I just automatically typed for loop in a right way when was checking it...) :-))
25th Apr 2017, 8:02 PM
Andrew Harchenko (Tomsk)
Andrew Harchenko (Tomsk) - avatar
+ 5
How can I recall report? :-) I'm sure it's not possible. :-( So... sorry devs watching those reports! 😇 I'm very sorry
25th Apr 2017, 8:10 PM
Andrew Harchenko (Tomsk)
Andrew Harchenko (Tomsk) - avatar
+ 5
@Rrestoring faith Lucky we are! ...having modern IDEs! ;)
25th Apr 2017, 8:24 PM
Andrew Harchenko (Tomsk)
Andrew Harchenko (Tomsk) - avatar
+ 4
@Tashi Done it already, but was disappointed that I can't give commentaries to my report. And wanted to commit code typed in playgrounds, so here it is.
25th Apr 2017, 7:40 PM
Andrew Harchenko (Tomsk)
Andrew Harchenko (Tomsk) - avatar
+ 4
[OOPS! I WAS WRONG, SEE BELOW] @Rrestoring faith "Measure twice, cut once". Done. And now any other can check (recheck) it after me. But to get easy access to question you should be in Sololearn team, right? Oh! I can make a screenshot and post it at some picture exchange site. Ok, wait a minute...
25th Apr 2017, 7:43 PM
Andrew Harchenko (Tomsk)
Andrew Harchenko (Tomsk) - avatar
+ 4
@Tashi N No I haven't suggested... emm... such (is it right to say so?) But any other sololearners who encountered that question and left it thinking "strange, there must be a typo somewhere I didn't notice" may now report it too. For example Sololearner whom I have challenged that type (has given wrong answer too which is not a surprize) and who liked this question already can report it too. That's what I suggest: the more reports the faster (wrong) question will be disintegrated! :-)
25th Apr 2017, 7:52 PM
Andrew Harchenko (Tomsk)
Andrew Harchenko (Tomsk) - avatar
+ 4
I know more tricky questions! One should exchange some latin "a" to a cyrillic "а" in code (exactly the same in most fonts) or even to "á" or at least write "Syslem.out.prlnt();"... you know... Just joking. ;-)
25th Apr 2017, 8:13 PM
Andrew Harchenko (Tomsk)
Andrew Harchenko (Tomsk) - avatar
+ 4
If someone wants question to be close to reality as much as possible they should add a voice of project manager who will ask every 5 second "Have you finished? Have you finished, yet?" (reminds me of "Shrek") ;-))) (Well, I don't have a job in development yet, but I already feel it... maybe there should be also "No-no-no! We wanted it to be fully the other way!")
25th Apr 2017, 8:19 PM
Andrew Harchenko (Tomsk)
Andrew Harchenko (Tomsk) - avatar
25th Apr 2017, 7:47 PM
Andrew Harchenko (Tomsk)
Andrew Harchenko (Tomsk) - avatar
+ 3
@Rrestoring faith We should do something about it. :-) But I don't know what. :-( Brainstorm?
25th Apr 2017, 8:16 PM
Andrew Harchenko (Tomsk)
Andrew Harchenko (Tomsk) - avatar