- /**
- * IfElseIf Demo:
- * Uses command line
input to input an integer. Outputs whether the
- * integer is a 1, 2, 3,
or not.
- *
- * @author (TK Rogers)
- * @version (11-26-07)
- */
-
- public class IfElseIf {
- public static void
main ( String args[] ) {
-
int test = 0;
-
int x = Integer.parseInt ( args[0] );
-
- if ( x == ++test
) {
-
System.out.println ( "The input was " + test );
- } else {
-
- if ( x == ++test
) {
-
System.out.println ( "The input was " + test );
- } else {
-
- if ( x == ++test
) {
-
System.out.println( "The input was " + test );
- } else {
-
-
System.out.println( "The input was not 1,2,3" );
// default
- }
- }
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////
- switch (x)
- {
-
case 1: {
-
System.out.println ( "The input was " + 1 );
-
break;
-
}
-
case 2: {
-
System.out.println ( "The input was " + 2 );
-
break;
-
}
-
case 3: {
-
System.out.println ( "The input was " + 3 );
-
break;
-
}
-
default: System.out.println ( "The input was not 1, 2, or 3" );
-
break;
- }
- }
- }