Sunday, January 22, 2017

Display weekday from day number using Switch Java

Tags

Following will help you understand:

/import java.util.*;
public class Weekday
{
   
    public static void main(String[] nt)
    {
     
        Scanner in=new Scanner(System.in);
        System.out.println("Enter Day Number");
        int a=in.nextInt();
        dayname(a);
       
    }
    public static void dayname(int c)
    {  String weekday;
        switch(c)
                {
                    case 1:weekday="Monday"; break;
                    case 2:weekday="Tuesday"; break;
                    case 3:weekday="Wednesday"; break;
                    case 4:weekday="Thrusday"; break;
                    case 5:weekday="Friday"; break;
                    case 6:weekday="Saturday"; break;
                    case 7:weekday="Sunday"; break;
                    default:System.out.println("Invalid day number");return;
                   
                }
        System.out.println("Weekday is "+weekday);
    }
   
}

Output: