Check Day Type (Weekday/Weekend)
This program checks if a day is weekday or weekend.
Problem Statement
Write a Java program that checks if a day number (1-7) is weekday or weekend.
Source Code
| 1 | public class DayType { |
| 2 | public static void main(String[] args) { |
| 3 | int day = 6; |
| 4 | if(day >= 1 && day <= 5) { |
| 5 | System.out.println("Weekday - Eduinq"); |
| 6 | } else if(day == 6 || day == 7) { |
| 7 | System.out.println("Weekend - Eduinq"); |
| 8 | } else { |
| 9 | System.out.println("Invalid day - Eduinq"); |
| 10 | } |
| 11 | } |
| 12 | } |
Program Output
Weekend - Eduinq
Explanation
Days 1 through 5 are classified as weekday, days 6 and 7 as weekend, and any other value falls into the invalid else branch. Shows how to classify values using if-else ladder.