OnJava8-Examples/control/VowelsAndConsonants.java
2015-09-07 11:44:36 -06:00

44 lines
1008 B
Java

// control/VowelsAndConsonants.java
// ©2015 MindView LLC: see Copyright.txt
// Demonstrates the switch statement.
import java.util.*;
import static com.mindviewinc.util.Print.*;
public class VowelsAndConsonants {
public static void main(String[] args) {
Random rand = new Random(47);
for(int i = 0; i < 100; i++) {
int c = rand.nextInt(26) + 'a';
printnb((char)c + ", " + c + ": ");
switch(c) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u': print("vowel");
break;
case 'y':
case 'w': print("Sometimes a vowel");
break;
default: print("consonant");
}
}
}
}
/* Output: (First 13 Lines)
y, 121: Sometimes a vowel
n, 110: consonant
z, 122: consonant
b, 98: consonant
r, 114: consonant
n, 110: consonant
y, 121: Sometimes a vowel
g, 103: consonant
c, 99: consonant
f, 102: consonant
o, 111: vowel
w, 119: Sometimes a vowel
z, 122: consonant
...
*/