A simple program in Java
Create a “Weekday calculator” for one month (e.g., for July 2019) in
Java that detects the weekday by the entered date (e.g., a user
inputs the date “19” and the program returns the result “The 19th of
July 2019 is Friday”)
Answers
Answered by
0
The program provided here is for the month of January 2021.
Program:
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int n;
string S[8] = {"","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
cout<<"Weekday calculator for January 2021"<<endl;
int c = 5; //because month of January 2021 starts with Friday
cout<<"Enter date : ";
cin>>n;
if(n>=1 && n<=31)
{
for(int i=1;i<n;i++)
{
if(c==7)
{
c=1;
}
else
{
c++;
}
}
cout<<"The "<<n<<"th of Janunary 2021 is "<<S[c];
}
else
{
cout<<"Invalid date";
}
}
Similar questions