
how can i make a program of even and odd using case statement?

Hi Friend,
Try the following code:
import java.util.*;
public class EvenOddExample{
public static void main(String[]args){
boolean status=false;
Scanner input=new Scanner(System.in);
System.out.println("Enter Numbers: ");
int arr[]=new int[10];
for(int i=0;i<arr.length;i++){
arr[i]=input.nextInt();
}
do{
System.out.println();
System.out.println("1 Display Even");
System.out.println("2 Display Odd");
System.out.println("3 Exit");
System.out.print("Choose Option: ");
int choice=input.nextInt();
switch(choice){
case 1:
for(int i=0;i<arr.length;i++){
if(arr[i]%2==0){
System.out.println(arr[i]);
}
}
break;
case 2:
for(int i=0;i<arr.length;i++){
if(arr[i]%2!=0){
System.out.println(arr[i]);
}
}
break;
case 3:
status=true;
System.exit(0);
break;
}
}
while(!status);
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.