Remainder Assignment Operator Help
Hello everyone. I'm completely new to java programming and need some help with using the remainder assignment operator. I want to make a program that calculates minutes that are inputed from a user, into years and days. I think I have the code to calculate the years correctly, but I don't know how to take the remainder from the result of the years calculation and translate it to days. When I input 1000000000 minutes, I get back 1902 years and 77 days. The correct answer should be 1902 years and 214 days. If anyone can point me in the right direction I would surely appreciate it. Thanks in advance.
import java.util.Scanner;
public class minuteCalc {
public static void main(String[] args) {
long minutes;
double hours;
double days;
double totalYears;
double totalDays;
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of minutes: ");
minutes = input.nextLong();
hours = minutes / 60;
days = hours / 24;
totalYears = (int)days / 365;
totalDays = (int)totalYears % 365; // ** this is the part I need help with **
System.out.println(minutes + " minutes is approximately " + totalYears + " years and " + totalDays + " days.");
}
}
Re: Remainder Assignment Operator Help
Obviously totalYears % 365 is not correct. Imagine I enter the exact number of minutes in 1 year. The output should by 1 year and 0 days. However 1 % 365 = 1. What you need to do is a subtraction. You already have the total number of days in the days variable so you need to reduce it by the number of days in totalYears.