Get startedGet started for free

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.

This exercise is part of the course

Input/Output and Streams in Java

View Course

Exercise instructions

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

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

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(____);
    }
}
Edit and Run Code