Problem: 3.17


 Question 3.17: Write a Java program that takes an integer number between 1 to 7 and displays the name of the weekday.

Test Data

Input number: 3

Expected Output:

Wednesday


Solution: 


package com.company;
import java.util.Scanner;
public class lab3problem17 {
    public static void main(String[] args) {
        Scanner Obj = new Scanner(System.in);
        while (true) {
            System.out.print("Enter any key 1 to 7: ");
            int n = Obj.nextInt();

            switch (n) {
                case 1: {
                    System.out.println("Sunday");
                    break;
                }
                case 2: {
                    System.out.println("Monday");
                    break;
                }
                case 3:
                {
                    System.out.println("Tuesday");
                    break;
                }
                case 4: {
                    System.out.println("Wednesday");
                    break;
                }
                case 5: {
                    System.out.println("Thuresday");
                    break;
                }
                case 6:{
                    System.out.println("Friday");
                    break;
                }
                case 7 :
                {
                    System.out.println("Saterday");
                    break;
                }
            }
        }
    }
}
Previous Post Next Post