10/02/2008

switch

switch is also used to define conditions.
int value or value that can be casted to int should be used, which are char, short and byte.
Usually break is necessary in each case block.
The default block can be placed first, second or anywhere.

switch (value) {
case 1:
    System.out.println("One");
    break;
case 2:
    System.out.println("Two");
    break;
case 3:
    System.out.println("Three");
    break;
default:
    System.out.println("Others");
}