Java Program to Convert Days into Years, Months and Days

This is a Java Program to Convert a Given Number of Days in terms of Years, Weeks & Days.

Enter any integer number as an input. After that we first divide the input by 365 to get number of years. After that we use modulus opeartion and division by 7 to get number of weeks. Finally we use modulo operation to get the number of days.

Here is the source code of the Java Program to Convert a Given Number of Days in terms of Years, Weeks & Days. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.

  1. import java.util.Scanner;
  2. public class Year_Week_Day 
  3. {
  4.     public static void main(String args[])
  5.     {
  6.         int m, year, week, day;
  7.         Scanner s = new Scanner(System.in);
  8.         System.out.print("Enter the number of days:");
  9.         m = s.nextInt();
  10.         year = m / 365;
  11.         m = m % 365;
  12.         System.out.println("No. of years:"+year);
  13.         week = m / 7;
  14.         m = m % 7;
  15.         System.out.println("No. of weeks:"+week);
  16.         day = m;
  17.         System.out.println("No. of days:"+day);
  18.     }
  19. }

Output:

$ javac Year_Week_Day.java
$ java Year_Week_Day
 
Enter the number of days:756
No. of years:2
No. of weeks:3
No. of days:5

Sanfoundry Global Education & Learning Series – 1000 Java Programs.

advertisement

Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
I’m Manish - Founder and CTO at Sanfoundry. I’ve been working in tech for over 25 years, with deep focus on Linux kernel, SAN technologies, Advanced C, Full Stack and Scalable website designs.

You can connect with me on LinkedIn, watch my Youtube Masterclasses, or join my Telegram tech discussions.

If you’re in your 40s–60s and exploring new directions in your career, I also offer mentoring. Learn more here.