BaşlayınÜcretsiz Başlayın

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.

Bu egzersiz

Input/Output and Streams in Java

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

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

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

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(____.____);
    }
}
Kodu Düzenle ve Çalıştır