1.

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 colorgreenSample Output 1:go

Answer»

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 }



Discussion

No Comment Found