This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

weel of something

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
: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
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try something to get a string randomly selected from Phr
and assign to pick.

HTH
[ November 16, 2003: Message edited by: chi Lin ]
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
A.Al-Ansari
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pleaae post your current code & we go from there
 
A.Al-Ansari
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry here it is

Your Best Ever...smile
 
chi Lin
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!