Day of the week from an integer

Report a typo

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".

Sample Input 1:

1

Sample Output 1:

Monday

Sample Input 2:

5

Sample Output 2:

Friday
Write 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