Computer Science, asked by Arnav92591, 1 month ago

Write a java program to demonstrate the road signaling with default as 'prepare to go' operation.

Assume red for 'stop', green for 'go', and yellow for 'proceed with caution'.

Answers

Answered by theresamary4866
3

Answer:

import java.util.Scanner;

public class Main{

   

   public static void main(String[] args){

       

      Scanner sc=new Scanner(System.in);

     

       System.out.println("Enter the color");

       String color=sc.next();

       

       switch(color){

           

           case "red":

               System.out.println("stop");

               break;

           

           case "green":

               System.out.println("go");

               break;

           

           case "yellow":

               System.out.println("proceed with caution");

               break;

               

           default:

               System.out.println("prepare to go");

               break;

       }

       

   }

   

}

Explanation:

Answered by sy4236207
2

Answer:

import java.util.Scanner;

public class Main{

public static void main(String[] args){

Scanner sc=new Scanner(System.in);

System.out.println("Enter the color");

String color=sc.nextLine();

String a="green";

String b="red";

String c="yellow";

if(a.equals(color))

{System.out.print("go");}

else if(b.equals(color))

{System.out.print("stop");}

else if(c.equals(color))

{System.out.print("proceed with caution");}

else

{System.out.println("prepare to go");}}}

Similar questions