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

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

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

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,884 questions

51,810 answers

573 users

How to convert days into human-readable weeks and days in Scala

1 Answer

0 votes
object Program {

  // Convert total days into a human‑readable "X weeks and Y days" string
  def toReadableWeeksDays(totalDays: Int): String = {
    val weeks = totalDays / 7      // whole weeks
    val days  = totalDays % 7      // leftover days

    s"$weeks week${if (weeks == 1) "" else "s"} and $days day${if (days == 1) "" else "s"}"
  }

  def main(args: Array[String]): Unit = {
    val days = 26
    
    println(toReadableWeeksDays(days))
  }
}




/*
run:

3 weeks and 5 days

*/

 



answered Dec 31, 2025 by avibootz

Related questions

...