Formulas within my code aren't cooperating

I'm a novice programmer and I am trying to solve this annoying problem with my code.

import java.util.Scanner;

public class TestLab100

{

public static void main(String[] args)

{

Scanner keyboard = new Scanner(System.in);

int milisec, sec, hour, minute, remainderMi, remainderS, remainderH, remainderM;

System.out.print("Starting milli-seconds: ");

milisec = keyboard.nextInt();

hour = milisec/ 3600000;

remainderH = milisec% 3600000;

minute = remainderH/ 60;

remainderS= minute/1000;

remainderM = minute%1000;

remainderMi = remainderM% 1000;

System.out.println("Hours: " + hour);

System.out.println("Minutes: " + remainderS);

System.out.println("Seconds: " + remainderM);

System.out.println("Milli Seconds: " + remainderMi);

}

}

I need the seconds to result in 40 and the milliseconds to be 123; well that's what they should be. Thanks for any help.

Re: Formulas within my code aren't cooperating

And what do you get printed instead?

Re: Formulas within my code aren't cooperating

--------------------Configuration: <Default>--------------------

Starting milli-seconds: 10000123

Hours: 2

Minutes: 46

Seconds: 668

Milli Seconds: 668

Process completed.

Re: Formulas within my code aren't cooperating

Also you need to show your input.

For easier testing, change the input statement by hardcoding a value. For example:

milisec = 12345; //keyboard.nextInt();

When you get your formulas working then you can restore it to get the user's input.

Re: Formulas within my code aren't cooperating

import java.util.Scanner;

public class TestLab100

{

public static void main(String[] args)

{

Scanner keyboard = new Scanner(System.in);

int milisec, sec, hour, minute, remainderMi, remainderS, remainderH, remainderM;

System.out.println("Starting milli-seconds: ");

milisec = 12345; //keyboard.nextInt();

hour = milisec/ 3600000;

remainderH = milisec% 3600000;

minute = remainderH/ 60;

remainderS= minute/1000;

remainderM = minute%1000;

remainderMi = remainderM% 1000;

System.out.println("Hours: " + hour);

System.out.println("Minutes: " + remainderS);

System.out.println("Seconds: " + remainderM);

System.out.println("Milli Seconds: " + remainderMi);

}

}

this is the output:

--------------------Configuration: <Default>--------------------

Starting milli-seconds:

Hours: 0

Minutes: 0

Seconds: 205

Milli Seconds: 205

Process completed.

Re: Formulas within my code aren't cooperating

Are the answers correct? Have you worked it out by hand to know what the correct answers are?

205 seconds looks like too many.

You need to take a piece of paper and pencil and do all the computations manually to see what the arithmetic is for computing each value.

Also to verify that your equations are doing what you expect, you should print out the results of ALL the steps. Looking at that printed output will tell you where your problem is.

Re: Formulas within my code aren't cooperating

well the original project was for my class and was to make 10000123 milliseconds into hours minutes and so on. I wanted to make it able to have user input though. For that (^) number of milliseconds it should be 2 hours, 46 minutes, 40 seconds, and 123 milliseconds. I am just confused on how the formulas should be. Again I am a novice programmer.

Re: Formulas within my code aren't cooperating

Quote:

I am just confused on how the formulas should be

This problem is pure arithmetic, very little programming required.

We'll start with two formulas:

How do you get the total number of seconds from millisecs?

How do you get the number of hours from a total number of seconds?

Re: Formulas within my code aren't cooperating

seconds = milliseconds/1000

hours = seconds/3600

Re: Formulas within my code aren't cooperating

How would you convert 7925 seconds to hours, minutes and seconds?

Can you do that on a piece of paper?

Re: Formulas within my code aren't cooperating

2 hours, 12 minutes, 5 seconds?

Re: Formulas within my code aren't cooperating

That looks right.

how did you do it? What were the steps you took to compute those values?

Write down the steps you used one by one.

That will be a guide for how to write the formulas for your program.

Re: Formulas within my code aren't cooperating

the seconds divided by 3600, the remaining number divided by 60, then the rest was the 5 seconds.

Re: Formulas within my code aren't cooperating

Your steps are not quite complete.

What is the "remaining number"? and What is the "rest"?

You need formulas to compute those values.

Re: Formulas within my code aren't cooperating

ill do the exact ones for this problem,

7925 divided by 3600 resulting in 2, then 725 divided by 60 resulting in 12, and then the remaining 5 seconds. Sorry if I'm not really good with this ha

Re: Formulas within my code aren't cooperating

Where did the 725 come from?

Where did the 5 come from?

What are the equations to compute those numbers?