w3resource

Java: Takes the user to input the minutes, and print the number of years and days for the minutes

Java Data Type: Exercise-4 with Solution

Convert Minutes to Years and Days

Write a Java program to convert minutes into years and days.

Test Data
Input the number of minutes: 3456789

Java datatype Exercises: Print the number of years and days from minutes

Sample Solution:

Java Code:

import java.util.Scanner;
public class Exercise4 {

    public static void main(String[] Strings) {


        double minutesInYear = 60 * 24 * 365;

        Scanner input = new Scanner(System.in);

        System.out.print("Input the number of minutes: ");

        double min = input.nextDouble();

        long years = (long) (min / minutesInYear);
        int days = (int) (min / 60 / 24) % 365;

        System.out.println((int) min + " minutes is approximately " + years + " years and " + days + " days");
    }
}

Sample Output:

Input the number of minutes: 3456789                                                                          
3456789 minutes is approximately 6 years and 210 days

Flowchart:

Flowchart: Java Data Type Exercises - Print the number of years and days from minutes

Java Code Editor :

Improve this sample solution and post your code through Disqus

Previous: Write a Java program that reads an integer between 0 and 1000 and adds all the digits in the integer. Input an integer between 0 and 1000.
Next: Write a Java program that prints the current time in GMT.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/java-exercises/datatypes/java-datatype-exercise-4.php