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:
/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: