package com.mindprod.example;
import static java.lang.System.*;
/**
* Demonstrate the use of switch and case.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0 2009-01-01
* @since 2009-01-01
*/
public final class TestSwitch
{
/**
* static per-class constant
*/
private static final int FIVE = 5;
/**
* instance per-object constant
*/
@SuppressWarnings( { "FieldMayBeStatic" } )
private final int SEVEN = 7;
/**
* demonstrate use of switch in an instance method
*/
private void process()
{
final int n = ( int ) ( System.currentTimeMillis() % 8 );
out.println( n );
final int SIX = 6;
switch ( n )
{
case 0:
out.println( "was 0" );
break;
case 1:
case 3:
out.println( "was 1 or 3" );
break;
case FIVE:
out.println( "was 5" );
break;
case SEVEN:
out.println( "was 7" );
return;
default:
out.println( "was 2, 4 or 6" );
}
}
/**
* Test harness
*
* @param args not used
*/
public static void main( String[] args )
{
new TestSwitch().process();
}
}