The switch case statement is useful when selecting some action from a number of alternatives. The value inside the test expression must be a int, char, short or byte. It can not be a long, double, float, string or any other other kind of object.The switch statement allows for any number of possible execution path.
The body of a switch statement is known as a switch block.
//Codding for Switch-case
class SwitchDemo { public static void main(String[] aggs) { int month= 8; switch(month) { case 1: System.out.prinln("January"); break; case 1: System.out.prinln("February"); break; case 1: System.out.prinln("March"); break; case 1: System.out.prinln("April"); break; case 1: System.out.prinln("May"); break; case 1: System.out.prinln("June"); break; case 1: System.out.prinln("July"); break; case 1: System.out.prinln("August"); break; case 1: System.out.prinln("September"); break; case 1: System.out.prinln("October"); break; case 1: System.out.prinln("November"); break; case 1: System.out.prinln("December"); break; default: System.out.prinln("Invalid month"); break; } } }
Happy codding..