Write a program that reads an integer between 1 and 7 from the user, representing a day of the week (1 for Monday, 2 for Tuesday, etc.). Using a switch statement, print the corresponding day of the week. If the input is not between 1 and 7, print "Invalid input".
Multiple conditions: switch
Day of the week from an integer
Report a typo
Sample Input 1:
1Sample Output 1:
MondaySample Input 2:
5Sample Output 2:
FridayWrite a program in Java 25
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Read an integer from the user
int dayNumber = scanner.nextInt();
// Use a switch statement to determine the day of the week
switch (dayNumber) {
// Add cases for each day of the week (1-7)
// Add a default case for invalid input
}
scanner.close();
}
}
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.