-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplay Weekday.java
More file actions
54 lines (47 loc) · 1.59 KB
/
Display Weekday.java
File metadata and controls
54 lines (47 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.Random;
import java.util.Scanner;
public class WeekdayGenerator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Random random = new Random();
// Prompt the user to enter a number between 1 and 7
System.out.print("Enter a number between 1 and 7: ");
int userInput = scanner.nextInt();
// Generate a random integer between 1 and 7
int randomNumber = random.nextInt(7) + 1; // Generates a number between 1 and 7
// Display the random number
System.out.println("Generated number: " + randomNumber);
// Determine the name of the weekday based on the random number
String weekday;
switch (randomNumber) {
case 1:
weekday = "Monday";
break;
case 2:
weekday = "Tuesday";
break;
case 3:
weekday = "Wednesday";
break;
case 4:
weekday = "Thursday";
break;
case 5:
weekday = "Friday";
break;
case 6:
weekday = "Saturday";
break;
case 7:
weekday = "Sunday";
break;
default:
weekday = "Invalid number"; // This case should never occur
break;
}
// Display the name of the weekday
System.out.println("The corresponding weekday is: " + weekday);
// Close the scanner
scanner.close();
}
}