Look at the java.lang.Integer class for one parsing option. I'll reiterate my suggestion to check out Sun's Java tutorials, get a reference book, or search the web: when I used Google to search for "java +convert string to number" I get a *lot* of relevant hits on the first page.
(And consider a code indentation style; it makes things much, much easier to read.)
i am familiar with converting strings to numbers, but that is not what i am trying to do, im trying to see if there is another method because i have to up the number of trial to 1000 and that is way to many variable to make.
Here's another way. If you mean that each character in the string represents a separate digit, then you can isolate each character and treat it as an integer by using a simple arithmetic expression. Have a look at the following page, and pay particular attention to the DEC (for decimal) and Symbol columns.
nathan gibson wrote:i am familiar with converting strings to numbers, but that is not what i am trying to do, im trying to see if there is another method because i have to up the number of trial to 1000 and that is way to many variable to make.
You said you were trying to add all the numbers in the string token--that implies converting each string representation of a number into a number and adding them. If the problem is something different, perhaps you could explain further. To get an average from the string tokens you just need to convert them to an integer in the loop you already have and add them, then divide, as you already stated.
@ david. my question is though, will that work with something like a thousand trials. i was trying to find something that would basically work like average = sumToken / counter. if you think your way would be suitable would you please list an example of the code that i would need?
It would work with a million trials: keep a sum, convert each token to an integer in the loop you already have, and add it to the sum. There's no need to create a new variable for each conversion--use the same one for the converted token, since you never need it again.
Happily living in the valley of the dried frogs with a few tiny ads.