Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Remainder Assignment Operator Help

1. ## 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.");

}
}

2. ## 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.