# can anyone help me please

• January 18th, 2013, 09:33 AM
dstevens
I need to use the modulous operator on this program. can anyone steer me in the correct direction. I am new to Java and I am trying to understand this language. Please help, my code is as follows

import java.util.Scanner;

public class Remainder {

public static void main (String args[]) {

int hour, min, sec, Total;

Scanner time = new Scanner(System.in);

System.out.print("Enter a number, 4 Digits long to recalculate the time!....");

Total= time.nextInt();
//hour = time.nextInt();
//min = time.nextInt();
//sec = time.nextInt();

min = Total / 60;
hour = min/60;
sec = Total/60;

int i = hour;
int j = min;
int h = sec;

System.out.println("Hours equal " + i);
System.out.println("Minutes equal " + j);
System.out.println("Seconds equal " + h);

int k = i % j;
System.out.println("i%j is " + j + " minutes");
}

}
• January 21st, 2013, 09:19 AM
AlexVV
Re: can anyone help me please
I'm guessing your input is a number of seconds .... so calculating hours is easy:
int hours = Total / 3600;
Minutes is where you need the modulus operator ... and divide the result by 60:
int mins = (Total % 3600) / 60;
And finally, seconds ... just divide by 60 as you have it.