Java Switch Example

Chapter: Control Statements Last Updated: 14-06-2016 16:49:03 UTC

Program:

            /* ............... START ............... */
                
public class JavaSwitchExample {

	public static void main(String args[]) {

		char grade = 'C';

		switch (grade) {
		case 'A':
			System.out.println("Excellent!");
			break;
		case 'B':
		case 'C':
			System.out.println("Well done");
			break;
		case 'D':
			System.out.println("You passed");
		case 'F':
			System.out.println("Better try again");
			break;
		default:
			System.out.println("Invalid grade");
		}
		System.out.println("Your grade is " + grade);
	}
}

                /* ............... END ............... */
        

Output

Well done
Your grade is C

Tags

Switch Statement, Java, Control Statements

Similar Programs Chapter Last Updated
Java For Loop And ForEach Loop Example Control Statements 03-09-2016
Java Enum And Switch Statement Control Statements 03-09-2016
Control Statements In Java Example Control Statements 19-06-2016
If Statement In Java Example Control Statements 17-06-2016
While Loop In Java Example Control Statements 08-06-2017
Return Statement In Java example Control Statements 15-07-2016
Print Stars In Java Example Control Statements 15-07-2016
Nested Loop In Java Example Control Statements 15-07-2016
Infinite While Loop In Java Control Statements 10-06-2016
Infinite Loop In Java Example Control Statements 15-07-2016
If Else Statement In Java Example Control Statements 10-06-2016
For Loop In Java Example Control Statements 07-06-2017
For Each In Java Example Control Statements 07-06-2017
Do While Loop In Java Example Control Statements 10-06-2016
Continue Statement In Java Example Control Statements 30-03-2017
Java Break Statement Example Control Statements 06-07-2016

1