Piet Souris wrote:Hi Allen,
welcome to the ranch and enjoy the stay!
Yes, it sounds allright. Problem to solve is getting the individual digits. Do you have an idea how to do that? And o yeah, as soon as you find an odd digit, you can stop the process. Why?
Campbell Ritchie wrote:Welcome to the Ranch again
Why are you using a counter? Why not stop the loop as soonn as an odd digit is found?
Campbell Ritchie wrote:I didn't see that post before replying. I am afraid I don't like that solution. For one thing you are repeating code; your expression is much too complicated. For another, there is something wrong with writing while (true).... Also I think your formula contains a serious logic error. No, I think there are two errors. Sorry.
Also the method name shoudn't start with a capital letter; I think isEven would be better.
Piet Souris wrote:Indeed it was similar.
It would be handy to assign each subcalculation to a variable, so that you can print out that variable to check if it is what you expect it to be.
So in Even, you could write
Then try n = 5 and see if Even reports an even or an odd result.
Tim Cooke wrote:zack redmen,
I have merged your topic into this topic. I hope that helps.
Dave Tolls wrote:Are there rules as to how you can and cannot calculate this?
Just wondering if you would be allowed to use a regex, for example.
Or just plain process the user input as a String, maybe.
If you have to work with an int in the sort of way you've written, rather than a do...while, recursion is an option.
Anyway, for the current solution, it's not obvious how this is supposed to exit.
I would expect more processing inside the loop.
'd' never gets reassigned, for example.
I would also expect there to be a return false in there if e%2 is not zero...after all, no point continuing once you have found an odd digit.
I am afraid it doesn't look like the sort of code that will work.
zack redmen wrote:. . . well it sort of works. . . . .