Computer Science, asked by aparimitak05, 11 months ago

Using switch statement in java wap to check and display whether the input by the user is even or odd​

Answers

Answered by Anonymous
2

Answer:

\huge\mathbf\green {Question :}

Using switch statement in java wap to check and display whether the input by the user is even or odd

{\blue{\underline{\underline{\huge {\bold{Answer:-}}}}}}

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");

}

}

}

\huge\mathfrak\red{Please\:Follow\:Me}

Similar questions