We would like to write a program that prompts the user to enter the minutes (e.g., 1 billion)
Display 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
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); // Prompt the user to enter the number of minutes System.out.print("Enter the number of minutes: "); int minutes = input.nextInt(); //your code /*from w w w.j a v a 2 s . c o m*/ // Display results System.out.println(minutes + " minutes is approximately " + years + " years and " + days + " days"); } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); // Prompt the user to enter the number of minutes System.out.print("Enter the number of minutes: "); int minutes = input.nextInt(); // Compute the number of years and days int years = minutes / 525600; int days = (minutes % 525600) / 1440; // Display results System.out.println(minutes + " minutes is approximately " + years + " years and " + days + " days"); } }
The following code shows the steps:
import java.util.Scanner; public class Main { public static void main(String[] Strings) { double minutesInYear = 60 * 24 * 365; Scanner input = new Scanner(System.in); System.out.print("Enter the number of minutes: "); double minutes = input.nextDouble(); long years = (long) (minutes / minutesInYear); int days = (int) (minutes / 60 / 24) % 365; System.out.println((int) minutes + " minutes is approximately " + years + " years and " + days + " days"); }/*ww w. j av a2 s . c om*/ }