LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Input/Output and Streams in Java

Kurs anzeigen

Anleitung zur Übung

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

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

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(____);
    }
}
Code bearbeiten und ausführen