Lesson 2.7 · Write it
Weekend check
A whole programPython or Java6 tests, 3 of them hidden
On a phone? Put the lines in order instead
Write a program that reads a day number (1 for Monday through 7 for Sunday) and prints whether it is a weekday or the weekend.
- Always print
Day:followed by the day number on the first line. - If the day is 6 (Saturday) or 7 (Sunday), print
Weekend. Otherwise, printWeekday. - Spaces at the end of a line are ignored.
- The day number is always between 1 and 7.
Your program is run several times. Only what it prints is checked.
Running Java here comes later. You can put this answer's lines in order instead. You can still write your Java answer (it stays while this page is open) and compare it with our worked solution. Or try this exercise in Python.
Examples
Your program is run 6 times: the 3 examples below, and 3 hidden ones that check the rules above. Only what it prints is checked.
Saturday: Weekend (rule 2)
You type
- typed: 6
It prints
Day: 6 Weekend
a weekday (rule 2)
You type
- typed: 3
It prints
Day: 3 Weekday
Sunday: Weekend (rule 2)
You type
- typed: 7
It prints
Day: 7 Weekend