始める無料で始める

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.

この演習はコースの一部です

Input/Output and Streams in Java

コースを見る

演習の手順

  • 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().

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

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(____.____);
    }
}
コードを編集して実行