Write a java program to find the day of the week. [N.B: day number must be taken from the user]
Answers
Answer:
import java.util.*; \\program starts
class prog \\class declaration
{ \\class block starts
public static void main(String args[])
{ \\main method starts
int day ; \\variable declaration
Scanner sc = new Scanner (System.in); \\creating object for input
System.out.println("Please enter the day number of the week to print day name of the week "); \\output statement asking input from user
day = sc.nextInt(); \\taking input from user
if(day<=7) \\condition checking if day number is less than 7
{ \\if block starts
if(day==1) \\condition for checking if day is 1
System.out.println("Day = Monday");
if(day==2) \\condition for checking if day is 2
System.out.println("Day = Tuesday");
if(day==3) \\condition for checking if day is 3
System.out.println("Day = Wednesday");
if(day==4) \\condition for checking if day is 4
System.out.println("Day = Thursday");
if(day==5) \\condition for checking if day is 5
System.out.println("Day = Friday");
if(day==6) \\condition for checking if day is 6
System.out.println("Day = Saturday");
if(day==7) \\condition for checking if day is 7
System.out.println("Day = Sunday");
} \\if block ends
} \\main method ends
} \\program ends