Using switch statement in java wap to check and display whether the input by the user is even or odd
Answers
Answered by
2
Answer:
Using switch statement in java wap to check and display whether the input by the user is even or odd
import java.io.*;
class switch
{
public static void main()throws IOException
{
DataInputStream in = new DataInputStream(System.in);
int n=0,ch=0;
double r=0;
System.out.print("Enter a number....:);
n=Integer.parseInt(in.readLine());
System.out.println("1.Even number....");
System.out.println("2.Odd number.....");
System.out.print("Enter your choice.....");
ch=Integer.parseInt(in.readLine());
r = n%2;
switch(ch)
{
case 1 : if(r==0)
System.out.print("Even number ");
break;
case 2 : if(r!=0)
System.out.print("Odd number");
break;
default: System.out.print("Your choice is not in the list");
}
}
}
Similar questions