Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Weekday Switch | Basic Types, Operations
Java Basics
course content

Course Content

Java Basics

Java Basics

1. Getting Started
2. Basic Types, Operations
3. Loops
4. Arrays
5. String

book
Challenge: Weekday Switch

Task
test

Swipe to begin your solution

Write a program that takes an integer from 1 to 7 and prints the corresponding day of the week.

  1. Use a switch statement to compare the value of day to numbers 1-7.
  2. For each case (1 to 7), print the corresponding day of the week.
  3. Add break after each case to prevent fall-through.
  4. Add a default case to handle invalid inputs (numbers outside 1-7). In this case, print "Error".

Solution

java

solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 7
toggle bottom row

book
Challenge: Weekday Switch

Task
test

Swipe to begin your solution

Write a program that takes an integer from 1 to 7 and prints the corresponding day of the week.

  1. Use a switch statement to compare the value of day to numbers 1-7.
  2. For each case (1 to 7), print the corresponding day of the week.
  3. Add break after each case to prevent fall-through.
  4. Add a default case to handle invalid inputs (numbers outside 1-7). In this case, print "Error".

Solution

java

solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 7
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
We're sorry to hear that something went wrong. What happened?
some-alt