Welcome to the Newschoolers forums! You may read the forums as a guest, however you must be a registered member to post.
Register to become a member today!
Anyone here good at java need help +k
Posts: 4295
-
Karma: 3,131
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
Posts: 4793
-
Karma: 1,370
if its divisible by 2, its even.
Posts: 4295
-
Karma: 3,131
ya i firgured that out my problem is applying that logic to a string
Posts: 52
-
Karma: 11
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.
Posts: 4295
-
Karma: 3,131
thank you so much i am always amazed at how many smart nsers there are!
Posts: 1498
-
Karma: 72
Posts: 1498
-
Karma: 72
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.
Posts: 4295
-
Karma: 3,131
thanks that should help allot
All times are Eastern (-5)