Computer Science, asked by anabolic390, 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'.

Sample Input 1:

Enter the color

green

Sample Output 1:

go

Answers

Answered by venkateshyadla282
36

Answer:

   1

   2 import java.util.Scanner;

   3  

   4 public class Main{

   5      

   6     public static void main(String[] args){

   7          

   8        Scanner sc=new Scanner(System.in);

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

  10        String color=sc.next();

  11        sc.nextLine();

  12        if(color=="green")

  13        {

  14            System.out.println("go");

  15        }

  16        else if(color=="red")

  17        {

  18            System.out.println("stop");

  19        }

  20        else if(color=="yellow")

  21        {

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

  23        }

  24        else

  25        {

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

  27        }

  28     }

  29 }

Answered by amansngrajput
11

Answer:

1.import java.util.Scanner;

2.public class Main{

3.public static void main(String[] args){

4.Scanner sc=new Scanner(System.in);

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

6.String color=sc.nextLine();

7.String a="green";

8.String b="red";

9.String c="yellow";

10.if(a.equals(color))

11.{

12.System.out.print("go");

13.}

14.else if(b.equals(color))

15.{

16.System.out.print("stop");

17.}

18.else if(c.equals(color))

19.{

20.System.out.print("proceed with caution");

21.}

22.else

23.{

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

25.}

26.}

27.}

Explanation:

Similar questions