Write a program in java using the switch – case to print the corresponding days of numbers.
[1=Sunday 2= Monday ……………]
Answers
Answer:
class WeekDays
{
public static void main(String s[])
{
int day = 2;
switch(day)
{
case 1:
System.out.println("Monday");
break;
case 2:
System.out.println("Tuesday");
break;
case 3:
System.out.println("Wednesday");
break;
case 4:
System.out.println("Thursday");
break;
case 5:
System.out.println("Friday");
break;
default:
System.out.println("Weekend");
break;
}
}
}
import java.util.*;
class Hello
{
public static void main (string args [])
{
Scanner sc=new Scanner(System .in);
int d;
System.out.println("Enter a day no.");
d=sc.nextInt();
switch=(d)
{
Case1: System.out.println("Monday");
break;
Case2: System.out.println("Tuesday");
break;
Case3: System.out.println("Wednesday");
break;
Case4: System.out.println("Thursday");
break;
Case5: System.out.println("Friday");
break;
Case6: System.out.println("Saturday");
break;
Case7: System.out.println("Sunday");
break;
default: System.out.println("Wrong Day");
}
}
}