ComenzarEmpieza gratis

Navigating with Enum

Enums are great for representing real-world directions clearly in code. Imagine you're creating a navigation feature for an application that provides instructions to users.

Este ejercicio forma parte del curso

Input/Output and Streams in Java

Ver curso

Instrucciones del ejercicio

  • Define an enum named Direction containing constants: NORTH, EAST, SOUTH, and WEST.
  • Create a method with Direction parameter.
  • Print the EAST direction using printDirection().

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

public class EnumDemo {
	// Define enum
    ____ Direction { 
        NORTH, EAST, SOUTH, WEST
    }

	// Method with enum parameter
    static void printDirection(____ direction) { 
        System.out.println("Direction: " + direction);
    }

	// Call method with EAST
    public static void main(String[] args) {
        printDirection(____);
    }
}
Editar y ejecutar código