Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Now I see what the problem was. I'm not a Java guy, but you should really stay away from using static variables (unless you know what you're doing), define them in function body instead.
Anyway, at least you solved it.
As you mentioned before, of cause there was an issue resetting the global var during recursion. In more detail the problewm was resetting the var if the input was a single digit after a sequence of inputs with multiple digit numbers.
Thank you for responsing. Have a nice day
Are you using recursion? It could be printing multiple values for single test in that case. There's no need to log values towards the end, because you'll see in console what was expected, and what you submitted.
Anyway, this is getting us nowhere. Could you post a screenshot of what you see when the tests fail? Or post your code here using proper markdown as
@Chrono79
mentioned above.It passes every test until the 0 test. I printed my output to see whats happening there and it seems that in this specific case my solution is not resetting.
It returns the last result again.
Maybe, when you use global vars and don't reset their values, it works fine the first time, but then it carries the last value and when called several times it produces wrong results.
Of cause im using global var. Does it affect the test negativly?
Yes it helps (but I'm only interested in initial values right now). So could you tell me what's the initial n, expected result and your result, for the failing test?
Read better.
Are you using some global var maybe? Post your code with proper markdown and mark your post as having spoiler content.
I already know the initial value since logging n at the beginning of the funtion. But if i log the sum before returning too, it maybe helps..
No... You need to know the initial value. Then you can reason about how it reaches expected result, etc. Logging it at the end can be useless, depending on what you're doing with that value.
Logging before returning the value seems to be a valid way to figure out why the test fails.
Thanks.
I will start some research soon
With n = 0, correct solution should be 0, that's correct... Are you logging at the beggining of the function? Try to see what console outputs for n when the test fails.
Btw, I solved this myself and I can assure you the tests are correct. Let's figure out where exactly you're failing.
I just dont know whats going on. I appreciate all the other solutions of cause.
As I already said: System.out.println(n) = 0. With this Input my solution returns 0 too. I have no clue, sorry :)
If the EXPEXTED value is 0, the only way to achieve this is with input 0
It's because the input isn't 0. That's the
EXPECTED
result. To see the input, log it usingSystem.out.prinln(n)
. Without input, I can't help you, but I'm 99% sure that the problem is in your code, and not the kata itself.Btw: Java Completions 9737. Are you saying all of them wrongfully solved this? :P
Loading more items...