Switch Statement In Java

0
Switch Statement In Java:-

It is called Jumping Statement in Java because we can jump into particular case according to option .

Switch provide group of options and we can jump into particular option.

switch(option)
{
     case option value:
          statement
          break
     case option value:
        statement
        break
     default:
        statement;
        break;

}

At run-time option will match from option value ,if option==option-value then that statement will be executed.


WAP to check even | odd using Switch Statement?

public class Main
{
    public static void main(String[] args) {
       int num=5;
       switch(num%2)
       {
             case 0:
                 System.out.print("Even");
                 break;
            default:
                 System.out.print("ODD");
                 break;
          
       }
    }
}


WAP to check greater number using Switch without if--else statement?

public class Main
{
    public static void main(String[] args) {
       int a=50;
       int b=10;
       switch(a/b)
       {
             case 0:
                 System.out.println("b is greater");
                 break;
            default:
                 System.out.println("a is greater");
                 break;
          
       }
    }
}


ASSIGNMENT OF SWITCH CASE:-

1) WAP to check Leap Year ?

2) WAP to check vowel and Cosnonent?

3) WAP to display "YES","NO" and "Cancel" When User Press 'Y','N' and 'C'?










إرسال تعليق

0تعليقات

POST Answer of Questions and ASK to Doubt

إرسال تعليق (0)