Write a Java program that reads a code (1-3) for a traffic signal and responds with the corresponding color. Use a switch statement. If the given input is not between 1 and 3, your program should output 'Invalid'.
Multiple conditions: switch
Decoding traffic signal colors from input codes
Report a typo
Sample Input 1:
1Sample Output 1:
GreenSample Input 2:
2Sample Output 2:
YellowWrite a program in Java 25
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// You can use nextLine method of scanner object to take the input from user
// Use a switch statement here to determine the color of the traffic signal
}
}
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.