Skip to content

Instantly share code, notes, and snippets.

@dmarquand
Last active June 21, 2017 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmarquand/84122537bec467bb8148f9eee9c099d7 to your computer and use it in GitHub Desktop.
Save dmarquand/84122537bec467bb8148f9eee9c099d7 to your computer and use it in GitHub Desktop.
firstProgram
import java.util.Scanner; //import scanner
public class FindFutureDates{
public static void main(String[] args){
Scanner input = new Scanner(System.in); //create a scanner object
System.out.println("Enter today's day:"); //ask user for integer
int dayIntInput = input.nextInt(); //assign next integer input to dayInt
String[] daysOfWeek = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; //make array of days of week
String firstDayOfWeek = daysOfWeek[dayIntInput]; //create string that holds value of first input converted to the name of the day
System.out.println("Enter the number of days elapsed since today: "); //ask user to input another number
int numberOfDaysInFuture = input.nextInt(); //create new variable based off user input
int firstDayPlusDaysInFuture = numberOfDaysInFuture + dayIntInput; //total number of days
String finalDay = daysOfWeek[firstDayPlusDaysInFuture%7];
System.out.println("Today is " + firstDayOfWeek + " and the future day is " + finalDay + "."); //final output with both days included
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment