Skip to content

Commit 8f41468

Browse files
committed
feat: Display day name based on numeric input (1–7) using conditional statements
🧠 Logic: - Takes an integer input from user. - Matches input (1–7) to corresponding weekday: - 1 → Monday, 2 → Tuesday, ..., 7 → Sunday. - If input is outside 1–7, prints "Invalid Day". Signed-off-by: Somesh diwan <[email protected]>
1 parent 4c60a93 commit 8f41468

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

Section7ConditionalStatements/src/ConditionalStatementsAB6.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//Print a day number based on given integer input
1+
//Print a day number based on a given, integer input.
22

33
import java.util.Scanner;
44

@@ -7,39 +7,30 @@ public static void main(String[] args) {
77
Scanner scan = new Scanner(System.in);
88

99
System.out.println("Enter a Day Number: ");
10-
1110
int day = scan.nextInt();
1211

13-
if(day==1)
14-
{
12+
if(day==1) {
1513
System.out.println("Monday");
1614
}
17-
else if (day == 2)
18-
{
15+
else if (day == 2) {
1916
System.out.println("Tuesday");
2017
}
21-
else if (day == 3)
22-
{
18+
else if (day == 3) {
2319
System.out.println("Wed");
2420
}
25-
else if (day == 4)
26-
{
21+
else if (day == 4) {
2722
System.out.println("Thursday");
2823
}
29-
else if (day == 5)
30-
{
24+
else if (day == 5) {
3125
System.out.println("Friday");
3226
}
33-
else if (day == 6)
34-
{
27+
else if (day == 6) {
3528
System.out.println("Saturday");
3629
}
37-
else if (day == 7)
38-
{
30+
else if (day == 7) {
3931
System.out.println("Sunday");
4032
}
41-
else
42-
{
33+
else {
4334
System.out.println("Invalid Day");
4435
}
4536
}

0 commit comments

Comments
 (0)