Falling Through

Home » Falling Through » Java » Falling Through

A real-life example of a switch statement with fall-through cases.

[code language=’java’] public class FallingThrough
{
public static void main(String[] args)
{
char c = ‘a’;

switch(c)
{
case ‘a’: // Falls-through
case ‘e’: // Falls-through
case ‘i’: // Falls-through
case ‘o’: // Falls-through
case ‘u’: // Falls-through
System.out.println("’"+ c +"’ is a vowel.");
break;

default:
System.out.println("’"+ c +"’ is a consonant.");
}
}
}
[/code] [geolocation]

Leave a Comment