+ 1
Can we use switch case in Java like as we use in c and c++?
3 Respuestas
+ 3
yes you can use switch case in Java too
example :
class SwitchDate{ public static void main(String[] args){ int week = 3; switch (week){ case 1: System.out.println("monday"); break; case 2: System.out.println("tuesday"); break; case 3: System.out.println("wednesday"); break; case 4: System.out.println("thursday"); break; case 5: System.out.println("friday"); break; case 6: System.out.println("saturday"); break; case 7: System.out.println("sunday"); break; default: System.out.println("Invalid week"); break; } } }
+ 3
Yes and it's exactly has the same syntax as we use it in c++
The only difference is that the (printing statement will change)
+ 1
thanks a lot