Computing.Net > Forums > Programming > Java Random Util help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Java Random Util help

Reply to Message Icon

Name: robc22
Date: February 11, 2004 at 16:29:57 Pacific
OS: Win XP
CPU/Ram: Pent 3 / 256 RAM
Comment:

Hi, I'm a beginning programmer and I have an assignment where I am using eclipse and have to write a program that produces 3 random capital vowels...like a slotmachine. I was wondering if I can get a little help because I'm a little lost. Thanks


RRRRR OOOOO BBBBB



Sponsored Link
Ads by Google

Response Number 1
Name: Infinite Recursion
Date: February 11, 2004 at 22:09:11 Pacific
Reply:

What do you have so far? Have you looked into Randomizing examples online? Have you attempted to begin coding?

IR


0

Response Number 2
Name: robc22
Date: February 12, 2004 at 07:43:00 Pacific
Reply:

well I know how to write code that will produce any random letter but i dont know how to produce just random vowels....I'm not sure what variables need to be set???


RRRRR OOOOO BBBBB


0

Response Number 3
Name: gpp
Date: February 12, 2004 at 13:06:48 Pacific
Reply:

Can you show us some code? We can tell you how to modify it.


0

Response Number 4
Name: iL_Huevo
Date: February 19, 2004 at 18:34:06 Pacific
Reply:

try

char c = 'random letter';

if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'){
codeeee...
codeee...
}

I don't remeber but I think that you should use an equal method instead of de ==

Hope it works

iL Huevo


0

Response Number 5
Name: Phoenixz33
Date: February 22, 2004 at 15:11:38 Pacific
Reply:

Or what you could do is construct an array of vowels if you've learned this already. Then, you can get a random number between 0 and 4 and use it to determine which of the vowels in the array should pop up.

For example:
char[] vowels = new char[5];
vowels[0] = 'a';
vowels[1] = 'e';
vowels[2] = 'i';
vowels[3] = 'o';
vowels[4] = 'u';
Random r = new Random();

And each time you want to get a random vowel:
int x = r.nextInt(5); //Brings up an integer between 0 and 4, inclusive

char thevowel = vowels[x];

And thevowel will have your vowel. Of course, if your class doesn't use char, you can always use String as well. Just replace char with String and you should be fine.

But if you haven't learned about arrays/arraylists/stuff like that, go with what iL_Huevo says. For char, == is right because it's a primitive data type. But for objects like strings, you should use equals() instead.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Java Random Util help

Java I/O Help www.computing.net/answers/programming/java-io-help/12986.html

Java Programming Exercise Help?? www.computing.net/answers/programming/java-programming-exercise-help/4289.html

Help in JAVA program www.computing.net/answers/programming/help-in-java-program/85.html