Switch Case Example In Java - Math Traders

Latest

Switch Case Example In Java

                Switch Case Example in Java


In this Java question we will understand the use of switch case in the Java that how we can use switch case in Java with an example program.

package ex1;
import java.util.*;

public class avg1 {

public static void main(String[] args) {
int num;
System.out.print("enter a number");
Scanner kb = new Scanner(System.in);
num = kb.nextInt();
switch(num)
    {
        case 1:
        System.out.print("n\\tentered number is 1");
    break;
    case 2:
    System.out.print("n\\tentered number is 2");
    break;
    default:
    System.out.print("n\\tentered number is neither 1 nor 2");
    }

}

}

No comments:

Post a Comment