Challenge: Weekday Switch
Opgave
Swipe to start coding
Write a program that takes an integer from 1 to 7 and prints the corresponding day of the week.
- Use a
switchstatement to compare the value ofdayto numbers 1-7. - For each case (1 to 7), print the corresponding day of the week.
- Add
breakafter each case to prevent fall-through. - Add a
defaultcase to handle invalid inputs (numbers outside 1-7). In this case, print"Invalid day".
Note
Please note that in our system, the counting of days in the week starts on Monday. So, the first day is Monday, the second is Tuesday, and so on.
Løsning
solution.java
Var alt klart?
Tak for dine kommentarer!
Sektion 2. Kapitel 8
single
Spørg AI
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat
Awesome!
Completion rate improved to 2.7
Challenge: Weekday Switch
Stryg for at vise menuen
Opgave
Swipe to start coding
Write a program that takes an integer from 1 to 7 and prints the corresponding day of the week.
- Use a
switchstatement to compare the value ofdayto numbers 1-7. - For each case (1 to 7), print the corresponding day of the week.
- Add
breakafter each case to prevent fall-through. - Add a
defaultcase to handle invalid inputs (numbers outside 1-7). In this case, print"Invalid day".
Note
Please note that in our system, the counting of days in the week starts on Monday. So, the first day is Monday, the second is Tuesday, and so on.
Løsning
solution.java
Var alt klart?
Tak for dine kommentarer!
Sektion 2. Kapitel 8
single