Computer Science, asked by Sherlockoo7, 4 months ago

Write a method Met that takes as parameter an integer.
This integer has value of the month. Depending on this you have to print the month's name. So if the value is 7, you should print july and if the value is 11 it will print november . If the integer is not in the correct range then it should return Invalid.

Answers

Answered by sangramsingh54
0

Answer:

The switch Statement

Use the switch (in the glossary) statement to conditionally perform statements based on an integer expression or enumerated type. Following is a sample program, SwitchDemo (in a .java source file), that declares an integer named month whose value supposedly represents the month in a date. The program displays the name of the month, based on the value of month, using the switch statement:

public class SwitchDemo {

public static void main(String[] args) {

int month = 8;

switch (month) {

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("Not a month!"); break;

}

}

}

The switch statement evaluates its expression, in this case the value of month, and executes the appropriate case (in the glossary) statement. Thus, the output of the program is August. Of course, you could implement this by using an if statement:

Answered by js7895383
0

Answer:

,‍♂️‍♀️‍♀️‍♀️‍♀️ਨਟਕਹਹਹਸਹਹਹਵreeyuooo

Similar questions