Switch Samples (Templates)
(Using SWITCH with integer values)
//Demo template program for SWITCH
import java.io.*;
import BreezyGUI.*;
public class switchtemplate
{
public static void main(String[ ] args)
{
int num = Console.readInt("Enter your favorite number from 1 to 5:");
switch (num)
{
case 1: {
System.out.println("One is the loneliest number.");
break;
}
case 2: {
System.out.println("Two is company.");
break;
}
case 3: {
System.out.println("Three is a crowd.");
break;
}
case 4: {
System.out.println("Four is a golf number.");
break;
}
case 5: {
System.out.println("High five!");
break;
}
default: {
System.out.println("You did not enter 1 - 5.");
break;
}
}
}
}
(Using SWITCH with character values)
//Demo template program for SWITCH
import java.io.*;
import BreezyGUI.*;
public class switchtemplate
{
public static void main(String[ ] args)
{
char letter = Console.readChar("Enter a, b, or c:");
{
case 'a': {
System.out.println("A-O-K.");
break;
}
case 'b': {
System.out.println("To B or not to B.");
break;
}
case 'c': {
System.out.println("C you soon.");
break;
}
default: {
System.out.println("You did not enter a, b or c.");
break;
}
}
}
}