Computer Science, asked by ayazturi96, 5 months ago

2b: Write a JavaScript program that asks the user to enter a number & check whether the number is even or odd using switch statement.​

Answers

Answered by kamalrajatjoshi94
2

Answer:

import java.util.*;

public class OddEven

{

public static void main(String args[])

{

Scanner in=new Scanner(System.in);

String choice;

System.out.println("Enter your choice");

choice=in.next();

switch(choice)

{

case 1:

int a;

System.out.println("Enter the number");

a=in.nextInt();

if(a%2==0)

{

System.out.println("The number is even");

else

System.out.println("Wrong Input");

}

break;

case 2:

int b;

System.out.println("Enter the number");

b=in.nextInt();

if(a%2!=0)

{

System.out.println("The number is odd");

else

System.out.println("Wrong input");

}

break;

default:

System.out.println("Wrong choice");

}

}

}

Similar questions