| Author |
weel of something
|
A.Al-Ansari
Greenhorn
Joined: Oct 18, 2003
Posts: 16
|
|
hi again ... i was reading the weel of future or sometihng code nad i came to try to modfy it as i want to make a random choics of the string array and pick one of them randomly .. then calculate its chars... but as laways i'm stucked..// i wasn to modify it after this problem ..to accept chars from user and then chech if its in the string or not.. the code it here/.. i'm stuvked didnt knew how to use random with string or how to cast it..// plz help..with alil explnation helping me to modfy it to.. Your Best Ever...smile
|
 |
chi Lin
Ranch Hand
Joined: Aug 24, 2001
Posts: 348
|
|
Math.random() give you a random number between 0.0(included) & 1.0 (excluded). If you want to get a number between 0 and 3 you could use Math.random()*3 and cast it to int. When you do the letter count, you are using UPcase letters, should use toUpperCase() from String to change pick to upper case before comparsion. HTH
|
 |
A.Al-Ansari
Greenhorn
Joined: Oct 18, 2003
Posts: 16
|
|
:roll: i tryed to use the Math.random // but i didnt knew how can i pick one string with in the array and assign it to the array// for(i=0; i<phr.length; i++){ pick = math.random * 3; i dont know how to assign one string from the phr to a variable in for loop so then i can use it under rndomly!! just 1 string.. will be picked from the list of string array(phr)... its some kind of verry simple game..// any other help plz! Your Best Ever...smile
|
 |
chi Lin
Ranch Hand
Joined: Aug 24, 2001
Posts: 348
|
|
Try something to get a string randomly selected from Phr and assign to pick. HTH [ November 16, 2003: Message edited by: chi Lin ]
|
 |
Chris Harris
Ranch Hand
Joined: Sep 21, 2003
Posts: 231
|
|
Hi, If I understand your question try : Note you may want to replace 3 with phr.length. If I understand your code correctly you do not need the loop: As you only ever want to pick one String for phr.length there is no need to loop. Hope that helps. Chris. [ November 16, 2003: Message edited by: Chris Harris ] [ November 16, 2003: Message edited by: Chris Harris ]
|
SCJP 1.2, SCWCD, SCBCD
|
 |
A.Al-Ansari
Greenhorn
Joined: Oct 18, 2003
Posts: 16
|
|
oh thanks... so by this asignment..it will atumatecly choose one from the phr// so i'll try it now thank's alot both of you
|
 |
A.Al-Ansari
Greenhorn
Joined: Oct 18, 2003
Posts: 16
|
|
i used the line but its just picking the first litter in the string not the first string why!! Your Best Ever...smile
|
 |
chi Lin
Ranch Hand
Joined: Aug 24, 2001
Posts: 348
|
|
|
pleaae post your current code & we go from there
|
 |
A.Al-Ansari
Greenhorn
Joined: Oct 18, 2003
Posts: 16
|
|
sorry here it is Your Best Ever...smile
|
 |
chi Lin
Ranch Hand
Joined: Aug 24, 2001
Posts: 348
|
|
Hi, In if clause, you are comparing only UpCase letter/character, so only first one letter on each subString was prcessed, all following lower ones are skipped. if((current >= 'A') && (current <= 'Z')) { one possible fix is convert pick to upcase before the toCharArray() call. HTH
|
 |
A.Al-Ansari
Greenhorn
Joined: Oct 18, 2003
Posts: 16
|
|
oh god it was really hidden and by the way i gues o i can include (and) in the for look to include lower case !! if its possible i'll try bth and see if it works thanks laot. Your Best Ever...smile
|
 |
 |
|
|
subject: weel of something
|
|
|