/**************************************************************************
* File: Example.java
* Title: Example Program for ILS614 (if, while, for)
* Programmer: Terry E. Weymouth
* Description: This program contains examples of the while, switch (case),
* for, if, and if else statements
* History:
* Created and debugged 02/08/96. TEW
*
* Last Modified on Thursday, February 8, 1996. TEW.
*
***************************************************************************/
public class Example {
private static void p(String theString) {
System.out.println(theString);
}
public static void main (String args[]) {
p(" ");
p("Starting Example");
p(" ");
int n;
n = 1;
while (n<5) {
p(" ");
p("While loop with n = " + n);
switch (n) {
case 1:
p("case one");
break;
case 2:
p("case two");
p("falls throught to...");
case 3:
p("case three");
break;
default:
p("any other case");
}
n = n + 1; // short hand ->> n++;
}
int i;
for (i=0;i<5;i++) {
p(" ");
p("For loop with i = " + i);
if (i < 3) {
p("i is less then three");
}
if (i > 4) {
p("i is greater then four");
}
else {
p("i is NOT greater then four");
}
if (i == 1) {
p("i is one");
p("that is all");
}
else if (i == 2) {
p("i is two");
p("what is new");
}
else if (i == 3) {
p("i is three");
p("this i see");
}
else {
p("what can i say");
}
} // end of the for loop! (whew)
p(" ");
p("Done.");
p(" ");
}
}