Welcome to The Forum

Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads

[Need Help][Java] Simple Program Confusion


Recommended Posts

For some odd reason I can not think how to do this correctly

 

The prompt is:

 

Design and Implement an application that determines and prints the number of odd,even,and zero digits in an integer value read from the keyboard.

 

 

The main twist is, I can't use Strings. Any help on this would be amazing!

Link to comment
Share on other sites

input a number

 

if number < 0: // Base case, if it is less than 0 you can't really count the digits, and it should be an integer anyway

return zerocount, evencount, oddcount or however you want to implement it

 

if number % 10 == 0: // This means that the number ends with a 0,

zerocount++

recursively call function (number / 10) // To get to the next digit

else if number % 2 == 1: // This means the number ends with a 1,3,5,7,9

oddcount++

recursively call (number / 10)

else: // Number is even

evencount++

recursively call (number / 10)

 

 

I'm not sure I quickly read over it and just wrote this up quickly, if you have any other questions I'll gladly help if I can

Edited by blue :D
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share