CSCI 201
Introduction to Algorithm Design home | homework index | labs index |
FALL 2006 |
In this lab we will finish developing class date
. This class actually
duplicates class Date
that's already built into Java, but this
is the best way to illustrate some important ideas.
The switch
statement is useful for expressing a certain type of
multi-way selection. A switch
statement allows you based on the
value of an expression jump to some location within the switch
statement. The expression must be either integer or character. It cannot be a
String
or a decimal number.
Example 1:
int n; .... //some code switch (n) { case 1: System.out.println("The number is 1"); break; case 2: case 4: System.out.println("The number is 2 or 4"); break; case 3: System.out.println("The number is 3"); break; default: System.out.println("The number is outside the range 1 to 4"); }
The break
statements are optional. They force flow of control to
the end of the switch statement. If you leave out the break
statement, the execution of the switch
statement will continue.
The specific rules for determining leap years are:
2004 is a leap year. 1900 is NOT a leap year.
If year is greater than 1752 (Gregorian Calendar) then
if ((Year % 4 == 0) && ( Year % 100 != 0 || Year % 400 == 0 )) Year is a Leap year