import java.util.Scanner; // Enables user input. public class FindDay { public s
ID: 3846069 • Letter: I
Question
import java.util.Scanner; // Enables user input.
public class FindDay {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int date = 0;
int day = 0;
System.out.println("Please enter a date in March 2016: ");
date = scnr.nextInt();
day = date % 7;
System.out.print("March " + date + " is a " );
// FIXME: Your solution goes in here...
return;
}
}
The month of March 2016 started on a Tuesday. Create a program with an integer date. Using modulus, report the day of the week this is.
Explanation / Answer
PROGRAM:-
import java.util.Scanner; // Enables user input.
class FindDay {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int date = 0;
int day = 0;
System.out.println("Please enter a date in March 2016: ");
date = scnr.nextInt();
day = date % 7;
System.out.print("March " + date + " is a " );
// FIXME: Your solution goes in here...
// Switch statement lets you deal with multiple if statements
switch(day){
case 0: System.out.println("Monday"); // we have assigned a case to each value of day
break;
case 1: System.out.println("Tuesday");
break;
case 2: System.out.println("Wednesday");
break;
case 3: System.out.println("Thursday");
break;
case 4: System.out.println("Friday");
break;
case 5: System.out.println("Saturday");
break;
case 6: System.out.println("Sunday");
break;
}
return;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.