66 951
Assignments Done
99,1%
Successfully Done
In October 2018

Answer to Question #3509 in Java | JSP | JSF for Y mukundareddy

Question #3509
4. Write a program using switch case to print the months in a year. If you give you give 1 to 12, it should print their respective months. [Example:- 1 for January, 2 for February and so on till 12 that i.e. December]
Expert's answer
import java.util.Scanner;


public class MonthPrinter
{
public static void main(String[] args)
{
System.out.print("Enter the digital number from 1 to 12: ");
Scanner sc = new Scanner(System.in);
int dayNumber = sc.nextInt();
switch (dayNumber)
{
case 1:
System.out.println("January");
break;
case 2:
System.out.println("February");
break;
case 3:
System.out.println("March");
break;
case 4:
System.out.println("April");
break;
case 5:
System.out.println("May");
break;
case 6:
System.out.println("June");
break;
case 7:
System.out.println("July");
break;
case 8:
System.out.println("August");
break;
case 9:
System.out.println("September");
break;
case 10:
System.out.println("October");
break;
case 11:
System.out.println("November");
break;
case 12:
System.out.println("December");
break;
default:
System.out.println("Wrong month number!");
break;
}
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions