Skip to content

Instantly share code, notes, and snippets.

@gitaficionado
Created September 28, 2019 13:44
Show Gist options
  • Save gitaficionado/b65311089e3bebe5d8f1e8776546e15b to your computer and use it in GitHub Desktop.
Save gitaficionado/b65311089e3bebe5d8f1e8776546e15b to your computer and use it in GitHub Desktop.
Write a program that prompts the user to enter an integer for today’s day of the week (Sunday is 0, Monday is 1, ..., and Saturday is 6). Also prompt the user to enter the number of days after today for a future day and dis-play the future day of the wk. See page pg. 100 for more details.
import java.util.Scanner;
public class FindFutureDates_03_05 {
public static void main(String[] args) {
// Prompt the user to enter an integer for today
System.out.print("Enter today’s day: ");
_________________________________________
System.out.print("Enter the number of days elapsed since today: ");
_____________________________________________
String nameForToday;
if (today == 0)
nameForToday = "Sunday";
else if (today == 1)
nameForToday = "Monday";
else if (today == 2)
nameForToday = "Tuesday";
else if (today == 3)
nameForToday = "Wednesday";
else if (today == 4)
nameForToday = "Thursday";
else if (today == 5)
nameForToday = "Friday";
else // if (today == 6)
nameForToday = "Saturday";
int futureDay = (today + elapsedDays) % 7;
String nameForFutureDay;
if (futureDay == 0)
nameForFutureDay = "Sunday";
else if (futureDay == 1)
nameForFutureDay = "Monday";
else if (futureDay == 2)
nameForFutureDay = "Tuesday";
else if (futureDay == 3)
nameForFutureDay = "Wednesday";
else if (futureDay == 4)
nameForFutureDay = "Thursday";
else if (futureDay == 5)
nameForFutureDay = "Friday";
else // if (futureDay == 6)
nameForFutureDay = "Saturday";
System.out.println("Today is " + _________________
+ " and the future day is " + _________________);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment