This program will show to you how switch statement execute by the java compiler.
import java.util.Scanner;
public class SampleSwitch
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
//declaration
int num;
System.out.print("Enter a number:");
num=input.nextInt();
Switch(num)
{
case 1:
case 3:
case 5:
case 7:
case 9:
System.out.print("You enter odd number:");
break;
case 2:
case 4:
case 6:
case 8:
case 10:
System.out.print("You enter even number:");
break;
default:
System.out.print("Your number you enter is not found in the case");
}
}
}
understand this program and practice to create your own program using switch statement,,
No comments:
Post a Comment