KnowledgeBoat Logo

Computer Applications

Write a program in Java to accept the number of days and display it after converting it into number of years, month & days.

Sample Input:
Enter the day number: 415

Sample Output:
1 Years 1 Months 20 Days

Java

Java Operators

86 Likes

Answer

import java.util.Scanner;

public class KboatDayConversion
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter days: ");
        int days = in.nextInt();
        int years = days / 365;
        days = days - (365 * years);
        int months = days / 30;
        int d = days - (months * 30);
        
        System.out.println(years + " Years " + months + " Months " + d + " Days");
    }
}

Output

BlueJ output of Write a program in Java to accept the number of days and display it after converting it into number of years, month & days. Sample Input: Enter the day number: 415 Sample Output: 1 Years 1 Months 20 Days

Answered By

35 Likes


Related Questions