Posted on 17th September 2024| views
A standard switch statement is just a statement that substitutes a range of simple if/else that performs necessary checks but it cannot replace all kind of if/else series it can only replace those which compare a value with some constant.
A small example of a switch statement is given below:
switch(choice)
{
case 1:
system.out.println(“fruits”);
case 2:
system.out.println(“leaves”);
case3:
system.out.println(“branches”);
default:
system.out.println(“not a tree”);
}