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
advertisement

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

If you find any mistake above, kindly email to [email protected]

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
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.