Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

help with math.random!

807599Apr 19 2007 — edited Apr 23 2007
I'm trying to replace all even numbers in a string with odd numbers that are produced from a random generator. I have somewhat of an idea of how to do it as far as creating an array of 5 characters(1,3,5,7,9) and then implement the math.random to take random numbers from that array. i just dont know how to execute that. for example:

"adam123456789" -->should be "adam153157739"

whereas, the underlined(5,1,7,3) should be random numbers(i just picked these for an instance). is it possible to do any form of :
Methods...
char [ ] ary = {1,3,5,7,9};
String line = "adam123456789";
line = line.replaceAll("[0,2,4,6,8]", Math.round(Math.random()*[ary]));
return line;
**i'm a beginner, so i dont really know what im talking about. just seeking help. thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 21 2007
Added on Apr 19 2007
17 comments
122 views