Java Day Number to Name switch Program

By | October 20, 2019

Task: Java Day Number to Name switch Program
Java Program – The Use of Switch Statement through practical Java programming- Input a day number from the user Display Day Name.

Java Day Number to Name switch Program

Java Day Number to Name switch Program

Source Code – Java Day Number to Name switch Program

/*
 * Java Program - The Use of Switch Statement
 * Input a day number from the user
 * Display Day Name
 */
package weekdays;

import java.util.Scanner;
/**
 *
 * @www.EasyCodeBook.com
 */
public class WeekDays {
   
    public static void main(String[] args) {
     int n;
      Scanner input=new Scanner(System.in);
      System.out.print("Enter day  number, I will tell you Day Name:");
      n=input.nextInt();
      switch(n)
      {
          case 1:
              System.out.println("Monday");
              break;
          case 2:
              System.out.println("Tuesday");
              break;
          case 3:
              System.out.println("Wednesday");
              break;
          case 4:
              System.out.println("Thursday");
              break;
          case 5:
              System.out.println("Friday");
              break;
          case 6:
              System.out.println("Saturday");
              break;
          case 7:
              System.out.println("Sunday");
              break;
          default:
              System.out.println("Invalid Day Number");    
      }
    }
    
}

Output of Converting Day Number to day Name Java Program

Enter day number, I will tell you Day Name:1
Monday

Enter day number, I will tell you Day Name:7
Sunday

Enter day number, I will tell you Day Name:5
Friday

Enter day number, I will tell you Day Name:9
Invalid Day Number

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *