Course Content
Java Basics
Java Basics
Challenge: Weekday Switch
Task
Swipe to begin your solution
Write a program that takes an integer from 1
to 7
and prints the corresponding day of the week.
- Use a
switch
statement to compare the value ofday
to numbers 1-7. - For each case (1 to 7), print the corresponding day of the week.
- Add
break
after each case to prevent fall-through. - Add a
default
case to handle invalid inputs (numbers outside 1-7). In this case, print"Error"
.
Solution
solution
Switch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?
Thanks for your feedback!
Section 2. Chapter 7
Challenge: Weekday Switch
Task
Swipe to begin your solution
Write a program that takes an integer from 1
to 7
and prints the corresponding day of the week.
- Use a
switch
statement to compare the value ofday
to numbers 1-7. - For each case (1 to 7), print the corresponding day of the week.
- Add
break
after each case to prevent fall-through. - Add a
default
case to handle invalid inputs (numbers outside 1-7). In this case, print"Error"
.
Solution
solution
Switch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?
Thanks for your feedback!
Section 2. Chapter 7
Switch to desktop for real-world practiceContinue from where you are using one of the options below