Friday, 14 September 2012

Java program codes: Switch Case Demo in JAVA

class SwitchDemo
{
public static void main(String args[])
{
 int month=Integer.parseInt(args[0]);
switch(month)
{

case 1: System.out.println("January");break;

case 2: System.out.println("February");break;

case 3: System.out.println("March");break;

case 4: System.out.println("April");break;

case 5: System.out.println("May");break;

case 6: System.out.println("June");break;

case 7: System.out.println("July");break;

case 8: System.out.println("August");break;

case 9: System.out.println("September");break;

case 10: System.out.println("October"); break;

case 11: System.out.println("November"); break;

case 12: System.out.println("October"); break;

default: System.out.println("Sorry ! invallied choice");break;

}
}
}

public class VowelsAndConsonants {
  public static void main(String[] args) {
    for(int i = 0; i < 100; i++) {
      char c = (char)(Math.random() * 26 + 'a');
      System.out.print(c + ": ");
      switch(c) {
      case 'a':
      case 'e':
      case 'i':
      case 'o':
      case 'u':
                System.out.println("vowel");
                break;
      case 'y':
      case 'w':
                System.out.println(
                  "Sometimes a vowel");
                break;
      default:
                System.out.println("consonant");
      }
    }
  }
}

No comments:

Post a Comment