Java Enum And Switch Statement

Chapter: Control Statements Last Updated: 03-09-2016 12:14:37 UTC

Program:

            /* ............... START ............... */
                
enum Car {
	lamborghini, tata, audi, fiat, honda
}

public class JavaEnumAndSwitch {

	public static void main(String args[]) {
		Car c;
		c = Car.tata;
		switch (c) {
		case lamborghini:
			System.out.println("You choose lamborghini!");
			break;
		case tata:
			System.out.println("You choose tata!");
			break;
		case audi:
			System.out.println("You choose audi!");
			break;
		case fiat:
			System.out.println("You choose fiat!");
			break;
		case honda:
			System.out.println("You choose honda!");
			break;
		default:
			System.out.println("I don't know your car.");
			break;
		}
	}
}
                /* ............... END ............... */
        

Output

You choose tata!

Tags

Enum And Switch Statement, Java, Control Statements

Similar Programs Chapter Last Updated
Java For Loop And ForEach Loop Example 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
Java Switch Example Control Statements 14-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