Decoding traffic signal colors from input codes

Report a typo

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'.

Sample Input 1:

1

Sample Output 1:

Green

Sample Input 2:

2

Sample Output 2:

Yellow
Write 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