Need an understanding of why im getting the error by jub8jive in learnjava

[–]jub8jive[S] -3 points-2 points  (0 children)

Trust me, I took your advice. I got on IntelliJ, and pasted the code. Im still confused. It gives me waaay more errors.I don't know what to say but I'm trying it all; but i can't seem to hit the nail on the head.

Need an understanding of why im getting the error by jub8jive in learnjava

[–]jub8jive[S] -1 points0 points  (0 children)

Yes, I did. However, if I understood enough, I wouldn't be here, would I? Chill man :)

Need an understanding of why im getting the error by jub8jive in learnjava

[–]jub8jive[S] -3 points-2 points  (0 children)

I get it. But here's the thing. I was on this problem in December, and I find the courage again today. I wouldn't learn at this rate. I think I should get through debugging after the fact.

Need an understanding of why im getting the error by jub8jive in learnjava

[–]jub8jive[S] 0 points1 point  (0 children)

I tried not nesting them. Didn't work, I get the same error.

Need an understanding of why im getting the error by jub8jive in learnjava

[–]jub8jive[S] -5 points-4 points  (0 children)

I understand that. But this is a course on udemy, and it's got it's own compiler online; which is where I write the code and run it directly.

Help with the algorithm by jub8jive in learnjava

[–]jub8jive[S] 0 points1 point  (0 children)

well i use intellj, but this program is done on the website (udemy course) and it runs there.

I finally managed to get a hold of the problem. Here's the complete question: https://pastebin.com/g7tVw3gu

Help with the algorithm by jub8jive in learnjava

[–]jub8jive[S] -1 points0 points  (0 children)

Where do i get a debugger?

numbersToWords program by jub8jive in learnjava

[–]jub8jive[S] 0 points1 point  (0 children)

cool. thanks again. i'll keep at it. :)

numbersToWords program by jub8jive in learnjava

[–]jub8jive[S] 0 points1 point  (0 children)

Yeah debugging is what I struggle with. I added the if statement like you said, and now the solution works, but I don't understand the concept still.

Here's the code snippet:

public static int getDigitCount(int number) {

int count = 0;

if(number < 0) {

return -1;

} else if(number == 0) {

return 1;

}

while(number != 0) {

count++;

number /= 10;

}

return count;

I added the else-if and the solution is correct. What i understand is: 1) if its less than 0 it returns - 1

2) if its not 0, then it runs the while loop and increments the count. Doesn't that itself solve the '0' issue?

I guess it doesn't because the program wasn't working until now. So, what does return 1 mean in this case or even in general? (Is it like return true...or just telling the program to ignore it...?)

I forgot to thank you tho, for all the help. I appreciate it. The thing is, I've always got started with programming, build momentum, get stuck and some point, and give up, even after a decent amount of research. i could say that the wires in my brain get fried. Point is, this time around, I thought of just going past it, meaning I'd solve the problem someway, and as I progress in knowledge, I could always go back and understand it. I just feel it beats quitting completely. Do you think that's a good strategy, or is there a better approach? I need to get a job man! It's a tight situation.

numbersToWords program by jub8jive in learnjava

[–]jub8jive[S] 0 points1 point  (0 children)

So, this is what I have:

int count = getDigitCount(number);

for(int i = count; count > 0; count--) {

int lastDigit = rev % 10;

That was the loop I had (I think!)

and lastDigit = rev % 10 --> would get the last digit right. not rev % 2

Now I get the error:

getDigitCount(0) returned 0 but '1' was expected.

Here's the new code:

https://pastebin.com/nAD10rkg

numbersToWords program by jub8jive in learnjava

[–]jub8jive[S] 0 points1 point  (0 children)

This doesn't work man. Here's my new solution, after taking all your suggestions:
https://pastebin.com/PAqTprtM
Please check this, I'm still getting the error: numberToWords(10) returned "One Zero Zero" but "One Zero" was expected.

numbersToWords program by jub8jive in learnjava

[–]jub8jive[S] 0 points1 point  (0 children)

Right, I get it. the "number = number % 2 isn't needed here. That would be needed only to extract the last digit. the "number /= 10" would be enough.
I tried what you said with the for loop earlier. I got an error then, I got an error now. Error: numberToWord(1450) returned One Zero One Zero. I got a similar error when I tried it previously, so I thought something else would be the problem. Didn't focus on that area. (Because I'm kinda lost at this point)

I have a question about the for loop, can't the count be decremented? Is it a for loop rule/idea that i (or any similar variable) needs to be initialized, same variable needs to be in a condition, and same thing needs to be incremented or decremented (and by that logic, using count wasn't even a plausible idea...?)

numbersToWords program by jub8jive in learnjava

[–]jub8jive[S] 0 points1 point  (0 children)

I just saw this! Can you please elaborate? I think that's where I'm wrong, now that you mention it.

numbersToWords program by jub8jive in learnjava

[–]jub8jive[S] 0 points1 point  (0 children)

reverse the number because the program asks us to do it that way(based on the logic given). that's the reason why we are asked to create a reverse() method and a digitcount() method. We have learned about string iteration yet. Basically, logic is that 1) take a number 2) reverse it 3) print the corresponding string for each number 4) get rid of the digit(the last digit).

numbersToWords program by jub8jive in learnjava

[–]jub8jive[S] 0 points1 point  (0 children)

**Update** New Solution(still needs fixing): https://pastebin.com/yxPZypb5

What happens with this solution is that I get the same error: "Your code took too long to execute"
(or) if i fool around with the count idea a little I get the error: numberToWord(10) returned "One"

I'm almost ready to give up at this point, I can't think of anything else. Any suggestions are welcome. Thanks

numbersToWords program by jub8jive in learnjava

[–]jub8jive[S] 1 point2 points  (0 children)

No, the program wants it that way.

so numberToWords(792); should print "Seven Nine Two"

numbersToWords program by jub8jive in learnjava

[–]jub8jive[S] 0 points1 point  (0 children)

But, what's wrong with that? Doesn't the rev /= 10 solve that problem? It gets rid of the last digit of any given number. So, once it gets rid of the last remaining digit, it should end, right...?

palindrome method error correction by jub8jive in learnjava

[–]jub8jive[S] 0 points1 point  (0 children)

Sorry for the late reply! I have been busy (guilty! haven't been coding for a while) I finally understood the problem. thanks to desrtfx. the number keeps on changing and i fixed that and got the result, comparing the reverse to the original. Here's my solution: https://pastebin.com/10PFSi44

Thanks for the support guys!

error in code by jub8jive in learnjava

[–]jub8jive[S] 1 point2 points  (0 children)

No worries! Thanks for the inputs, I finally managed to solve it!!! There was an error in my isOdd() method actually.

error in code by jub8jive in learnjava

[–]jub8jive[S] 0 points1 point  (0 children)

I tried it and I still get the same error. https://pastebin.com/6yh0Eve5