Computer Science, asked by eakshithkarri, 5 months ago

write a java switch case program to accept a number between 1 to 12 and print the coresponding month ​

Answers

Answered by Anonymous
4

Answer:

The switch statement allows us to execute a block of code among many ... the syntax of the switch statement is cleaner and much easier to read and write. ... Enter first number: 12 Enter second number: 23 Invalid operator!

Answered by tiwarishashwat125
1

Answer:

import java.util.Scanner;

 

public class NumberOfDays {

     public static void main(String[] args) {

           Scanner in = new Scanner(System.in);

           System.out.print("Enter month's number: ");

           int monthNumber;

           monthNumber = in.nextInt();

           switch (monthNumber) {

           case 1:

           case 3:

           case 5:

           case 7:

           case 8:

           case 10:

           case 12:

                 System.out.println("Number of days: 31");

                 break;

           case 4:

           case 6:

           case 9:

           case 11:

                 System.out.println("Number of days: 30");

                 break;

           case 2:

                 System.out.println("Number of days: 28");

                 break;

           default:

                 System.out.println("Invalid month.");

                 break;

 

           }

     }

}

Enter month's number: 5

Number of days: 31

Explanation:

Similar questions