Java Program to Demonstrate Switch Case (JNNC Technologies)


This Java program is used to show the use of switch case to display the month based on the number assigned.
Example:
class monthno {
 public static void main(String argu[]) {
  int mnth = 6;
  switch (mnth) {
   case 1:
    System.out.println("Showing Month: January");
    break;
   case 2:
    System.out.println("Showing Month: February");
    break;
   case 3:
    System.out.println("Showing Month: March");
    break;
   case 4:
    System.out.println("Showing Month: April");
    break;
   case 5:
    System.out.println("Showing Month: May");
    break;
   case 6:
    System.out.println("Showing Month: June");
    break;
   case 7:
    System.out.println("Showing Month: July");
    break;
   case 8:
    System.out.println("Showing Month: August");
    break;
   case 9:
    System.out.println("Showing Month: September");
    break;
   case 10:
    System.out.println("Showing Month: October");
    break;
   case 11:
    System.out.println("Showing Month: November");
    break;
   case 12:
    System.out.println("Showing Month: December");
    break;
   default:
    System.out.println("Invalid input - Wrong month number.");
    break;
  }
 }
}

Post a Comment

0 Comments

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();