In this tutorial, You will be learning writing Java Programs to print the weekdays for the given week in numeric form.
For Example:
Suppose the user has given input 3
Then the output should be Tuesday.
Program to print weekday for a given input week
import java.util.*;
public class Main
{
public static void main (String[]args)
{
System.out.println("Print week name for given week in Java");
Scanner sc = new Scanner (System.in);
System.out.println ("Please enter a Week number");
int num = sc.nextInt();
if(num==1)
System.out.println("Sunday");
else if(num==2)
System.out.println("Monday");
else if(num==3)
System.out.println("Tuesday");
else if(num==4)
System.out.println("Wednesday");
else if(num==5)
System.out.println("Thursday");
else if(num==6)
System.out.println("Friday");
else if(num==7)
System.out.println("Saturday");
else
System.out.println("Please Enter Between 1 to 7 ");
}
}
Output 1:
Print week name for given week in Java
Please enter a Week number
4
Wednesday