105k views
3 votes
Write a program that prompts the user to enter the minutes (e.g., 1 billion), and displays the number of years and days for the minutes. For simplicity, assume a year has 365 days. Here is a sample run: Enter the number of minutes: 1000000000 1000000000 minutes is approximately 1902 years and 214 days

User Hadi Teo
by
8.4k points

1 Answer

2 votes

Answer:

// here is code in java.

import java.util.*;

// class definition

class Solution

{

// main method of the class

public static void main (String[] args) throws java.lang.Exception

{

try{

// scanner object to read innput

Scanner s=new Scanner(System.in);

// variables

long min,years,days;

long temp;

System.out.print("Please enter minutes:");

// read minutes

min=s.nextLong();

// make a copy

temp=min;

// calculate days

days=min/1440;

// calculate years

years=days/365;

// calculate remaining days after years

days=days%365;

// print output

System.out.println(temp+" minutes is equal to "+years+" years and "+days+" days");

}catch(Exception ex){

return;}

}

}

Step-by-step explanation:

Read the number of minutes from user and assign it to variable "minutes" of long long int type.Make a copy of input minutes.Then calculate total days by dividing the input minutes with 1440, because there is 1440 minutes in a day.Then find the year by dividing days with 365.Then find the remaining days and print the output.

Output:

please enter the minutes:1000000000

1000000000 minutes is equal to 1902 years and 214 days.

User MrCroft
by
8.4k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.