• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Asking about "string" data type of JAVA

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi sir,
hope u r doin' fine .i m having some problems in the String data type of JAVA so plz help me out.The problem is given below:
Write a program to display a random choice from a set of six choice of (i.e breakfastApple,Orange,Grappes,Pineapple,Strawbery&Bannana)
i hope sir taht u will get me this answer asap.
i really appriaciate your concern
with regards
Kumar Abhay
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

One solution to ur prob :-
Store the Strings in an array ... ok ...
since there are 6 strings ... generator a random integer between 0 and 5 (inclusive) ... and get the Random String using the number as the index to the array !! ...
String array[] = {oranges, apples.....};
String randomString = array[java.math.random() * 5 ];


Originally posted by kumar abhay:
hi sir,
hope u r doin' fine .i m having some problems in the String data type of JAVA so plz help me out.The problem is given below:
Write a program to display a random choice from a set of six choice of (i.e breakfastApple,Orange,Grappes,Pineapple,Strawbery&Bannana)
i hope sir taht u will get me this answer asap.
i really appriaciate your concern
with regards
Kumar Abhay


 
kumar abhay
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi sir,
hope u r doin' fine.thanx alot for ur reply.but sir i have not done array yet so is it possible doing it without using array.i will wait for ur replay,till then take care n bye
kumar abhay
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well the array idea was really good. If you HAVE to avoid that (so I suppose you would have to avoid a Map also) you could just generate a random number from 1 to 6 and then use a switch statement

Or you COULD do a nested if statement 6 layers deep:
 
kumar abhay
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi sir,
i hope u r doin' fine.thanks alot for your precious concern regarding my problem it really helped me alot. I hope sir that u will continue it in the future.take care
with regards
kumar abhay
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why do you say 'sir' so often ??? (if you don't mind me asking)
it's funny allright

regards,
Dave
 
kumar abhay
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi there,
i call u sir bec i think u deserve it.thats y i m asking n u r replying sir.take care
with regards
kumar abhay
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that it is very nice . Although in America we usually call ladies "ma'am" .
http://www.javaranch.com/contact.jsp#Glass
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic