Click here to watch in Youtube :
https://www.youtube.com/watch?v=hd-3sUYhENw&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Java Tutorial : Java switch statement |
Java Tutorial : Java switch statement |
class SwitchDemo { public static void main(String[] args) { int month = 3; String monthValue; switch (month) { case 1: monthValue = "January"; break; case 2: monthValue = "February"; break; case 3: monthValue = "March"; break; case 4: monthValue = "April"; break; case 5: monthValue = "May"; break; case 6: monthValue = "June"; break; case 7: monthValue = "July"; break; case 8: monthValue = "August"; break; case 9: monthValue = "September"; break; case 10: monthValue = "October"; break; case 11: monthValue = "November"; break; case 12: monthValue = "December"; break; default: monthValue = "Invalid month"; break; } System.out.println("Month is : "+monthValue); } }
Month is : March
public class IfThenElseDemo { public static void main(String[] args) { int month = 3; String monthValue; if (month == 1) { monthValue = "January"; } else if (month == 2) { monthValue = "February"; } else if (month == 3) { monthValue = "March"; } else if (month == 4) { monthValue = "April"; } else if (month == 5) { monthValue = "May"; } else if (month == 6) { monthValue = "June"; } else if (month == 7) { monthValue = "July"; } else if (month == 8) { monthValue = "August"; } else if (month == 9) { monthValue = "September"; } else if (month == 10) { monthValue = "October"; } else if (month == 11) { monthValue = "November"; } else if (month == 12) { monthValue = "December"; } else { monthValue = "Invalid month"; } System.out.println("Month is : " + monthValue); } }
Month is : March
https://sites.google.com/site/javaee4321/java/ControlFlowDemoSwitchApp.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/ControlFlowDemoSwitchApp
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/08783475a968761a2cf4b3fc7275842653545b35/BasicJava/ControlFlowDemoSwitchApp/?at=master
See also:
No comments:
Post a Comment