Weekdays Using a Switch Statement in Java

Weekdays using a switch statement in java. This Java software can assist you in determining the weekdays order. The user is prompted to input a valid week number in the program below. Check the week number using the switch case after collecting the value from the user program and display the relevant day. I assumed, like the previous program, that Monday is the beginning day of the week.

import java.util.Scanner;
public class Main
public static void main(String[] args)
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the week days");
int weekday = scanner.nextInt();
if(weekday == 1)
} else if(weekday == 2)
} else if(weekday == 3) {
} else if(weekday == 4) {
} else if(weekday == 5) {
} else if(weekday == 6) {
} else if(weekday == 7) {
} else {
System.out.println("Enter the numbers between 1 to 7");



Enter the week days

If Else Statement in Java

In Java, the if statement is used to execute a block of code if a condition is true. If a condition evaluates to false, the if…else statement is used alongside an if statement to run code. The if…else…if phrase is also used to test several conditions. The simplest basic decision-making statement in Java is the if statement. 

It is used to determine if a statement or a block of statements will be executed or not, that is if a condition is true, a block of statements will be performed; otherwise, it will not.

Else If Statement in Java

Otherwise known as else f, else if is a conditional statement that is executed after an if statement and runs a function if true. The above example might be expanded by including as many else if and else if statements as the application required. Note. All programming languages are not created equal. Using this program write a program to print the day of the week using switch statement in java.