Hey there! This problem might be a bit unpredictable, but give it a go and let us know how you do!
Create an enum called Weekday with constants for MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY and SUNDAY. Each enum constant should have an associated integer value representing the day of the week (e.g., MONDAY=1, TUESDAY=2, etc.). Write a program that prompts the user to enter a day of the week as an integer (1-7) and prints the corresponding enum constant name.Computer scienceProgramming languagesJavaCode organizationObject-oriented programmingOther conceptsEnumerations
Combining constants with enum
Enum weekday from integer input
Report a typo
Sample Input 1:
1Sample Output 1:
MONDAYSample Input 2:
5Sample Output 2:
FRIDAYWrite a program in Java 17
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int dayNumber = scanner.nextInt();
Weekday day = Weekday.values()[dayNumber - 1];
System.out.println(day);
}
}
enum Weekday {
// Define the enum constants here
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
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.