Home » Java Programs » Java Basic Programs

# Java program to convert a given number of days into years, weeks, days

Given number of days, we have to convert a given number of days into years, weeks, days.

Submitted by Nidhi, on February 26, 2022

**Problem Solution:**

In this program, we will read the number of days from the user and convert them into years, weeks, days.

**Program/Source Code:**

The source code to convert a given number of days into days, weeks, and years is given below. The given program is compiled and executed successfully.

// Java program to convert a given number of days // into days, weeks, and years import java.util.Scanner; public class Main { public static void main(String[] args) { int ndays = 0; int years = 0; int weeks = 0; int days = 0; Scanner X = new Scanner(System.in); System.out.print("Enter days: "); ndays = X.nextInt(); years = ndays / 365; weeks = (ndays % 365) / 7; days = (ndays % 365) % 7; System.out.printf("%d years, %d weeks and %d days\n", years, weeks, days); } }

**Output:**

Enter days: 567 1 years, 28 weeks and 6 days

**Explanation:**

In the above program, we imported the "*java.util.Scanner*" package to read input from the user. And, created a public class Main. It contains a static method *main()*.

The *main()* method is an entry point for the program. Here, we read the number of days from the user using the *Scanner* class. Then we converted them into years, weeks, and days. After that, we printed the result.

Related Programs

- Java program to swap two numbers using function
- Java program to check number is positive, negative or zero
- Java program to find largest number among three numbers
- Java program to check whether year is Leap year or not
- Java program to demonstrate example of enum data type
- Java program to demonstrate example of this keyword
- Java example for while loop demonstration
- Java example for do while loop demonstration
- Java program to calculate HCF of two numbers
- Java program to multiply two numbers using plus (+) operator
- Java program to perform subtraction without using minus (-) operator
- Java program to print the value in decimal, octal, hexadecimal using printf() method
- Java program to calculate the employee and employer provident fund
- Java program to calculate the gratuity of an employee
- Java program to compare float and double values
- Java program to find the remainder without using modulus (%) operator
- Java program to check a given character is alphanumeric or not without using a built-in method
- Java program to check a given character is a digit or not without using the built-in library method
- Java program to check a given character is a whitespace character or not without using the built-in library method
- Java program to check a given character is an uppercase character or not without using the built-in library method
- Java program to check a given character is a lowercase character or not without using the built-in library method
- Java program to check a given character is a punctuation mark or not without using the built-in library method
- Java program to check a given character is a printable character or not without using the built-in library method
- Java program to find the roots of a quadratic equation
- Java program to find the (GCD) Greatest Common Divisor
- Java program to find the (LCM) Lowest Common Multiple

- Java program to calculate the area of a triangle based on given three sides
- Java program to calculate the area of a triangle based on a given base and height
- Java program to calculate the area of Trapezium
- Java program to calculate the area of Rhombus
- Java program to calculate the area of Parallelogram
- Java program to calculate the area of Cube
- Java program to find the Surface Area and volume of the cylinder
- Java program to calculate the surface area, volume, and space diagonal of cuboids
- Java program to calculate the surface area and volume of Cone
- Java program to calculate the surface area and volume of Sphere
- Java program to calculate the mean, variance, and standard deviation of real numbers
- Java program to read coordinate points and determine its quadrant
- Java program to calculate the value of nCr
- Java program to calculate the value of nPr
- Java program to calculate the product of two binary numbers
- Java program to add two complex numbers
- Java program to extract the last two digits from a given year
- Java program to read the height of the person, and the print person is taller, dwarf, or average height person
- Java program to find the sum of two numbers using binary addition
- Java program to find subtraction of two numbers using binary subtraction
- Java program to extract bytes from an integer (Hex) value
- Java program to convert hexadecimal byte to decimal
- Java program to read a weekday number and print weekday name using switch statement

Comments and Discussions!