1. WAP to accept a number from the user (1-7) and print the corresponding day (eg:1 -Sunday)
Answers
import java.util.Scanner;
public class Days
{
public static void main (String args[])
{
Scanner sc=new Scanner (System.in);
System.out.print("Please enter day number: ");
int dayN = sc.nextInt();
if (dayN == 1)
{
System.out.println("Monday");
}
else if (dayN == 2)
{
System.out.println("Tuesday");
}
else if (dayN == 3)
{
System.out.println("Wednesday");
}
else if (dayN == 4)
{
System.out.println("Thursday");
}
else if (dayN == 5)
{
System.out.println("Friday");
}
else if (dayN == 6)
{
System.out.println("Saturday");
}
else if (dayN == 7)
{
System.out.println("Sunday");
}
else
{
System.out.print("Invalid Day Number Entered");
}
sc.close();
}
}