Is there anyway to find day n string of Nth Days from given days in String ?
Calculating Nth days from the given number of days in String, shown below:
For Example :
If the user enters the day: Monday
and
the nth day: 11
Then the output will be: Thursday
Table of Contents
Java Program Code
/*;==========================================
; Title: Calculate the Nth days from the given number of days in String.
; Author: codenaive littleboy8506@
; Date: 13 Dec 2021
;==========================================*/
import java.util.*;
public class CountDay{
public static void main(String []args){
String day;
Scanner obj=new Scanner(System.in);
String array[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
int num;
int count=0;
System.out.println("Enter the Day : ");
day=obj.nextLine();
System.out.println("Enter the nth Day : ");
num=obj.nextInt();
for(int i=0;i<7;i++)
{
if(day.toUpperCase().equals(array[i].toUpperCase()))
{
count=i;
break;
}
}
for(int i=0;i6)
{
count=0;
}
}
System.out.println("The Day is : "+array[count]);
}
}
Output
Enter the Day :
Monday
Enter the nth Day :
1
The Day is : Tuesday
Leave a Reply