← Back to Miscellaneous
Question 155
Enum Traffic Light with if
Enum Traffic Light with if
Use a Java enum and an if statement to determine and print the action for a traffic light. The enum Light is already declared. Set the current light toLight.GREEN, then use if to check: print 'Go' if GREEN, otherwise print 'Stop'. With enums, always use == for comparison, not .equals().
Expected Output:
Go= newline. The output ends with a newline — print one after the last line.
Hints3 available
Sign in to use hintsTopics:
Miscellaneous
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.