Switch statements in java

GOCOURSE


Switch statements:

            Switch statements are the multi-way branching statements ,it is used to select one  among many code blocks to be executed .

Syntax:

switch(expression)
{

 case 1:
    break;

case 2:
     break;

default:
}

Program:

public class Main
{
public static void main(String[] args)
{
int signals = 3;
switch (signals)
{
case 1:
System.out.println("RED");
break;
case 2:
System.out.println("YELLOW");
break;
case 3:
System.out.println("GREEN");
break;
default:
System.out.println("this is traffic signal");
}
}
}

Output:

GREEN


Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send