Here is a program to check weather the inputted character is a vowel or a consonent. It also uses the switch case mechanism to determine the vowel property of the character. Function Math.random() is used to generate an arbitary character and then checks weather the caharacter is a vowel or consonent.
* A program to implement the usage of the switch case in java lang…
* @author jo
* @author [email@example.com]
* It uses a method – Math.random(). generates a value between 0 and 1, you need
* only multiply it by the upper bound of the range of numbers you want to
* produce (26 for the letters in the alphabet) and add an offset to establish
* the lower bound.
public static void
x = Math
.random() * 26;
c = (char)(
x + ‘a’);
* Math.random( ) produces a double, so the value 26 is converted to a
* double to perform the multiplication, which also produces a double.
* This means that ‘a’ must be converted to a double to perform the
* addition. The double result is turned back into a char with a cast.
.println("Math.random()*26 >> "+
c + ": ");
case ‘u’: System
case ‘w’: System
.println("Sometimes a vowel");