Computer Science, asked by jsprashantchouhan, 4 months ago

Write a program in java to accept a day number, using switch case print the corresponding day name. ​

Answers

Answered by dreamrob
3

Program:

import java.util.*;

public class MyClass {

   public static void main(String args[])

   {

       Scanner Sc = new Scanner(System.in);

       int ch;

       System.out.print("1:Monday\n2:Tuesday\n3:Wednesday\n4:Thursday\n5:Friday\n6:Saturday\n7:Sunday\nEnter your choice : ");

       ch = Sc.nextInt();

       switch(ch)

       {

           case 1:

               System.out.print("The day corresponding to " + ch + "is Monday");

               break;

           case 2:

               System.out.print("The day corresponding to " + ch + "is Tuesday");

               break;

           case 3:

               System.out.print("The day corresponding to " + ch + "is Wednesday");

               break;

           case 4:

               System.out.print("The day corresponding to " + ch + "is Thursday");

               break;

           case 5:

               System.out.print("The day corresponding to " + ch + "is Friday");

               break;

           case 6:

               System.out.print("The day corresponding to " + ch + "is Saturday");

               break;

           case 7:

               System.out.print("The day corresponding to " + ch + "is Sunday");

               break;

           default:

               System.out.print("Invalid day number");

       }

   }

}

Similar questions