public class RandomCharacters {
private static void doRandomCharacters() {
double randomNumber;
double randomNumberSetup;
char randomCharacter;
System.out.println("----------------------------------------------------------------------");
for (int i = 0; i < 10; i++) {
randomNumber = Math.random();
randomNumberSetup = (randomNumber * 26 + 'a');
randomCharacter = (char) randomNumberSetup;
System.out.print(randomCharacter + ": ");
switch(randomCharacter) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u': System.out.print("vowel");
break;
case 'y':
case 'w': System.out.print("sometimes a vowel");
break;
default: System.out.print("consonant");
}
System.out.println(" - Random number was (" + randomNumber + ")");
}
System.out.println("----------------------------------------------------------------------");
System.out.println("\n");
}
/**
* Sole entry point to the class and application.
* @param args Array of String arguments.
*/
public static void main(String[] args) {
doRandomCharacters();
}
}
Monday, October 20, 2008
to generate random characters
link
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment