Anyone here good at java need help +k

cool_name

Active member
how would i go about finding out how many odd numbers and even numbers are inside a string? i know how to tell if a number is odd or even but i cant figure out how to apply the concept to a string?

help would be very appreciated
 
Use the charAt function to get each individual character in the string (you'll have to use a for loop from i=0 to the length of the string). For each character, convert it to a number. If it's ASCII you can just subtract the appropriate value and typecast it. Once it is a number, use the % operator to test if it is divisible by two. Have two counter variables (one for evens, one for odds) and increment the appropriate one.
 
stupid mobile... if youre struggling i find that the api is extremely helpful for getting unstuck when using unfamiliar data structures. if youre going to be programming more in java, then you should bookmark it. good luck and pm me if you need any more java help.
 
Back
Top