Computer Science, asked by gauravsinghania6717, 17 days ago

WAP in Java to allow user to input a number between 1 to 10 and print whether it is odd or
Even number.(Using Switch Case)

Answers

Answered by ItzMeSam35
1

import java.util.Scanner;

public class SwitchExample {

public static void main(String [] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Please input a number between 1 and 10 : ");

int num = sc.nextInt();

switch(num) {

case 1 :

case 3 :

case 5 :

case 7 :

case 9 :

System.out.println("Odd number");

break;

case 2 :

case 4 :

case 6 :

case 8 :

case 10 :

System.out.println("Even number");

break;

default :

System.out.println("Invalid number entered");

break;

}

sc.close();

}

}

Similar questions