KnowledgeBoat Logo

Computer Applications

Write a Java program using the switch case to print the corresponding days of numbers.

For example: 1= Monday…. 7 = Sunday

Java

Java Conditional Stmts

46 Likes

Answer

public class KboatDayName
{
    public static void dayName(int n) {
        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("Incorrect day.");
        }
    }
}

Output

BlueJ output of Write a Java program using the switch case to print the corresponding days of numbers. For example: 1= Monday…. 7 = Sunday

Answered By

14 Likes


Related Questions