Source code for SwitchExample4.java:

public class SwitchExample4
{
	public static void main(String args[])
	{
		// SwitchExample4
		char grade;
		String rating;
		// Later
		grade = 'B';
		switch (grade)
		{
			case 'A':
				rating = "Excellent";
				break;
			case 'B':
				rating = "Good";
				break;
			case 'C':
				rating = "Average";
				break;
			case 'D':
				rating = "Poor";
				break;
			case 'F':
				rating = "Failure";
				break;
			default:
				rating = "Confused";
		}
		System.out.println("Grade is " + grade);
		System.out.println("Rating is " + rating);
	}
}

Output from SwitchExample4.java:

Grade is B Rating is Good

--- Output Ends ---

NOTE:

You are reading previously generated output. You are not currently running the SwitchExample4 application at the momement. You need to compile and run the source code first.

To run this program:


Authors: Kevin Chu and Eric Brower
Copyright 2000 Prentice Hall PTR