Java Program to Read a Weekday Number and Print Weekday Name Using Switch Statement

You are currently viewing Java Program to Read a Weekday Number and Print Weekday Name Using Switch Statement

Java program to read a weekday number and print weekday name using switch statement

// Java program to read a weekday number and 
// print weekday name using switch statement

import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner SN = new Scanner(System.in);
    int wDay = 0;

    System.out.printf("Enter weekday number (0-6): ");
    wDay = SN.nextInt();

    switch (wDay) {
    case 0:
      System.out.printf("Sunday");
      break;

    case 1:
      System.out.printf("Monday");
      break;

    case 2:
      System.out.printf("Tuesday");
      break;

    case 3:
      System.out.printf("Wednesday");
      break;

    case 4:
      System.out.printf("Thursday");
      break;

    case 5:
      System.out.printf("Friday");
      break;
    case 6:
      System.out.printf("Saturday");
      break;

    default:
      System.out.printf("Invalid weekday number.");
    }
    System.out.printf("\n");
  }
}

Output

Enter weekday number (0-6): 5
Friday

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply