Ad
  • Default User Avatar

    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.

  • Default User Avatar

    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

  • Default User Avatar

    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.

  • Default User Avatar

    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.

  • Custom User Avatar

    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.

  • Default User Avatar

    Of cause im using global var. Does it affect the test negativly?

  • Default User Avatar

    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?

  • Custom User Avatar

    continue reducing in this way until a single-digit number is produced.

    Read better.

  • Custom User Avatar

    Are you using some global var maybe? Post your code with proper markdown and mark your post as having spoiler content.

  • Default User Avatar

    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..

  • Default User Avatar

    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.

  • Default User Avatar

    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

  • Default User Avatar

    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.

  • Default User Avatar

    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

  • Default User Avatar

    It's because the input isn't 0. That's the EXPECTED result. To see the input, log it using System.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...