You include the boolean type, and your cases use int types. But even if you change your business to boolean types, this will not work. You cannot enable the boolean type. And that makes no sense, since using if-else would be simpler:
if (isOn) { System.out.println("its on"); } else { System.out.println("its off"); }
Please note that there is no "I don't know!" . The boolean type can be true or false . This is another reason why switch-case not for boolean type. There is no default case.
You can also condense it into a single statement using a conditional expression:
public void test(boolean isOn) { System.out.println(isOn ? "its on" : "its off"); }
Rohit jain
source share