Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Disclosure: My content contains affiliate links.

43,239 questions

56,142 answers

573 users

How to print every month in a specified year that contains five full weekends (Fri, Sat, Sun) in Kotlin

1 Answer

0 votes
// A month has five full weekends when it has 31 days,
// and the 1st day of the month is a Friday.

import java.time.DayOfWeek
import java.time.LocalDate

// ------------------------------------------------------------
// Month names as a single reusable constant
// ------------------------------------------------------------
val monthNames = listOf(
    "January", "February", "March", "April", "May", "June",
    "July", "August", "September", "October", "November", "December"
)

// ------------------------------------------------------------
// Function: returns true if a month has 5 full weekends
// ------------------------------------------------------------
fun hasFiveFullWeekends(year: Int, month: Int): Boolean {
    val firstDay = LocalDate.of(year, month, 1)

    val daysInMonth = firstDay.lengthOfMonth()
    val weekday = firstDay.dayOfWeek

    return (daysInMonth == 31 && weekday == DayOfWeek.FRIDAY)
}

// ------------------------------------------------------------
// Main program
// ------------------------------------------------------------
fun main() {
    val yValue = 2026

    for (m in 1..12) {
        if (hasFiveFullWeekends(yValue, m)) {
            println("${monthNames[m - 1]} $yValue has five full weekends.")
        }
    }
}


/*
run:

May 2026 has five full weekends.

*/

 



answered May 27 by avibootz

Related questions

...