Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Program to Convert a Given Number of Days in terms of Years, Weeks & Days in Kotlin


Source Code:
import java.util.Scanner

fun main(args: Array) {
    var totalDays: Int
    val years: Int
    val weeks: Int
    val days: Int
    val s = Scanner(System.`in`)
    print("Enter the number of days:")
    totalDays = s.nextInt()
    years = totalDays / 365
    weeks = (totalDays % 365) / 7
    days = (totalDays % 365) % 7
    println("No. of years:$years")
    println("No. of weeks:$weeks")
    println("No. of days:$days")
}

Output:
Enter the number of days:366
No. of years:1
No. of weeks:0
No. of days:1

Description:
In the above program,  we have taken input from a user to enter the number of days as an Integer input. Next, we have used an equation "years = Totaldays / 365" to find the number of years from the total number of days entered.

To find the total number of weeks, we have used an equation "weeks = (totalDays % 365) / 7". And to find days, an equation is "days = (totalDays % 365) % 7".




This post first appeared on Ask For Program, please read the originial post: here

Share the post

Program to Convert a Given Number of Days in terms of Years, Weeks & Days in Kotlin

×

Subscribe to Ask For Program

Get updates delivered right to your inbox!

Thank you for your subscription

×