English, asked by veeraphanindrakumar, 11 months ago

Write a program to print month in words, based on input month in numbers.(using switch case)

Answers

Answered by idris7
0

Explanation:

This program asks a user to input any number equal to or between 1-12. It then converts the number to a message that will be printed (Copy the program to see it yourself). Is there a way to make the code shorter by still using the switch statement?

This is homework, so using a switch is a requirement.

Answered by Brenquoler
48

import java.util.*;

class Hello

{

public static void main (string args [])

{

Scanner sc=new Scanner(System .in);

int d;

System.out.println("Enter a month no.");

d=sc.nextInt();

switch=(d)

{

Case1: System.out.println("January");

break;

Case2: System.out.println("February");

break;

Case3: System.out.println("March");

break;

Case4: System.out.println("April");

break;

Case5: System.out.println("May");

break;

Case6: System.out.println("June");

break;

Case7: System.out.println("July");

break;

Case8: System.out.println("August");

break;

Case9: System.out.println("September");

break;

Case10: System.out.println("October");

break;

Case11: System.out.println("November");

break;

Case12: System.out.println("December");

break;

default: System.out.println("Wrong Month");

}

}

}

Similar questions