<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Converting Seconds into Minutes, Hours and Seconds... HELP!(PartII)' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Converting Seconds into Minutes, Hours and Seconds... HELP!(PartII)' posted on the 'Java' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Wed, 19 Jun 2013 11:54:02 -0700</pubDate>
    <lastBuildDate>Wed, 19 Jun 2013 11:54:02 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Converting Seconds into Minutes, Hours and Seconds... HELP!(PartII)</title>
      <link>http://www.programmersheaven.com/mb/java/316213/316213/converting-seconds-into-minutes-hours-and-seconds-helppartii/</link>
      <description>Well this is for the second part of the assignment.. Fock.&lt;br /&gt;
I dont know why I can't seem to figure this out.&lt;br /&gt;
But I think once I get these two down.. I should have a pretty good understanding.&lt;br /&gt;
Now my program is prompting me to INITIALIZE my variables.. and I dont understand why.&lt;br /&gt;
&lt;br /&gt;
Here's what I got. What I'm suposed to be able to do with this one, is type in a value..&lt;br /&gt;
Total Seconds:___&lt;br /&gt;
And then Convert it into&lt;br /&gt;
Hours:&lt;br /&gt;
MinuteS: &lt;br /&gt;
Seconds:&lt;br /&gt;
&lt;br /&gt;
If you could help me out with why this isnt working, that would be awesome.&lt;br /&gt;
import&lt;br /&gt;
 java.util.Scanner;&lt;br /&gt;
&lt;br /&gt;
 class StoHMS&lt;br /&gt;
 {&lt;br /&gt;
 public static void main (String[] args) // Main input.&lt;br /&gt;
	{&lt;br /&gt;
		int minutes, hours, seconds, timeInSeconds = 0; //declaration of variables.&lt;br /&gt;
		timeInSeconds = timeInSeconds - (hours * 3600);&lt;br /&gt;
		Scanner scan = new Scanner (System.in); // declaration of scanner class.&lt;br /&gt;
		&lt;br /&gt;
		System.out.print ("Enter the number of seconds: ");&lt;br /&gt;
		timeInSeconds = scan.nextInt();&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
			hours = timeInSeconds / 3600;&lt;br /&gt;
			timeInSeconds += minutes * 60;&lt;br /&gt;
			timeInSeconds += seconds;  &lt;br /&gt;
		&lt;br /&gt;
		 System.out.println(hours + " hours: ");&lt;br /&gt;
		 System.out.println( + minutes + " minutes: ");&lt;br /&gt;
		 System.out.println( + seconds + " seconds");&lt;br /&gt;
  &lt;br /&gt;
		}&lt;br /&gt;
}&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java/316213/316213/converting-seconds-into-minutes-hours-and-seconds-helppartii/</guid>
      <pubDate>Sat, 24 Sep 2005 22:07:22 -0700</pubDate>
      <category>Java</category>
    </item>
    <item>
      <title>Re: Converting Seconds into Minutes, Hours and Seconds... HELP!(PartII</title>
      <link>http://www.programmersheaven.com/mb/java/316213/316215/re-converting-seconds-into-minutes-hours-and-seconds-helppartii/#316215</link>
      <description>&lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by Vilanye at  2005-9-25 0:58:5&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
Lets walk through your program:&lt;br /&gt;
&lt;br /&gt;
int minutes, hours, seconds, timeInSeconds = 0; &lt;br /&gt;
&lt;br /&gt;
The reason you are getting the errors that minutes, hours and seconds might not have been initialized is because only timeInSeconds was initialized to 0. You have to explicitly initialize each one&lt;br /&gt;
&lt;br /&gt;
int minutes=0, hours=0, seconds=0, timeInSeconds = 0;//this will fix the compiler errors.&lt;br /&gt;
&lt;br /&gt;
From here on, I will assume that the corrected line above is part of your program. This will help point out your logic errors. If you had used minutes and seconds the way it should have been, the compiler would not have cared if they were initialized. It only cares when you try to use them uninitialized. &lt;br /&gt;
&lt;br /&gt;
What is the point of this next line?&lt;br /&gt;
&lt;br /&gt;
timeInSeconds = timeInSeconds - (hours * 3600);&lt;br /&gt;
&lt;br /&gt;
At this point timeInSeconds and hours are both 0. 0-(0*3600) is 0. This does nothing. What are you trying to accomplish here?&lt;br /&gt;
&lt;br /&gt;
Next 3 lines:&lt;br /&gt;
&lt;br /&gt;
 Scanner scan = new Scanner (System.in); // declaration of scanner class.&lt;br /&gt;
&lt;br /&gt;
System.out.print ("Enter the number of seconds: ");&lt;br /&gt;
timeInSeconds = scan.next();&lt;br /&gt;
&lt;br /&gt;
This is fine, but timeInSeconds overwrites what was done earlier. If the line right after the declaration and initialization actually did anything, that work would be wiped out here.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
hours = timeInSeconds / 3600;//no problem here use this line to fix the next line&lt;br /&gt;
&lt;br /&gt;
timeInSeconds += minutes * 60;//not quite&lt;br /&gt;
&lt;br /&gt;
The above line is equivalent to timeInSeconds = timeInSeconds + minutes * 60. Assuming that the user entered 30, it would be timeInSeconds = 30 + 0 *60. Which is 30, exactly what was entered by the user and not what you need. In short this does nothing.&lt;br /&gt;
 &lt;br /&gt;
Presumably you want to convert seconds into minutes. Rethink the arithmetic using the way you got hours as a guide.&lt;br /&gt;
&lt;br /&gt;
timeInSeconds += seconds;//this is pointless&lt;br /&gt;
&lt;br /&gt;
The way you have the program written this is timeInSeconds = timeInSeconds + seconds. seconds is set to 0. So it changes the value to the exact value it was. You really do not need a seconds variable since timeInSeconds will be equivalent.&lt;br /&gt;
&lt;br /&gt;
 System.out.println(hours + " hours: ");//this is fine&lt;br /&gt;
System.out.println( + minutes + " minutes: ");//This might cause a compiler error&lt;br /&gt;
System.out.println( + seconds + " seconds");//ditto, instead of using seconds, just use timeInSeconds.&lt;br /&gt;
&lt;br /&gt;
I am not sure if the compiler will complain about the last 2 lines. + is the concatenation operator, it is a binary operator, meaning it uses 2 operands. + minutes is only one operand, lose the first + on the last 2 lines. Even if it does compile, ditch the first + on those lines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like I said before tracing the code on paper is extremely helpful. If you would have spent 10 minutes doing this you likely would have figured out the semantic and syntax errors on your own. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;&lt;span style="color: Blue;"&gt;Just my 2 bits&lt;/span&gt;&lt;em&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/em&gt;&lt;/em&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java/316213/316215/re-converting-seconds-into-minutes-hours-and-seconds-helppartii/#316215</guid>
      <pubDate>Sun, 25 Sep 2005 00:54:20 -0700</pubDate>
      <category>Java</category>
    </item>
    <item>
      <title>Re: Converting Seconds into Minutes, Hours and Seconds... HELP!(PartII</title>
      <link>http://www.programmersheaven.com/mb/java/316213/316256/re-converting-seconds-into-minutes-hours-and-seconds-helppartii/#316256</link>
      <description>: &lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by Vilanye at  2005-9-25 0:58:5&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
: Lets walk through your program:&lt;br /&gt;
: &lt;br /&gt;
: int minutes, hours, seconds, timeInSeconds = 0; &lt;br /&gt;
: &lt;br /&gt;
: The reason you are getting the errors that minutes, hours and seconds might not have been initialized is because only timeInSeconds was initialized to 0. You have to explicitly initialize each one&lt;br /&gt;
: &lt;br /&gt;
: int minutes=0, hours=0, seconds=0, timeInSeconds = 0;//this will fix the compiler errors.&lt;br /&gt;
: &lt;br /&gt;
: From here on, I will assume that the corrected line above is part of your program. This will help point out your logic errors. If you had used minutes and seconds the way it should have been, the compiler would not have cared if they were initialized. It only cares when you try to use them uninitialized. &lt;br /&gt;
: &lt;br /&gt;
: What is the point of this next line?&lt;br /&gt;
: &lt;br /&gt;
: timeInSeconds = timeInSeconds - (hours * 3600);&lt;br /&gt;
: &lt;br /&gt;
: At this point timeInSeconds and hours are both 0. 0-(0*3600) is 0. This does nothing. What are you trying to accomplish here?&lt;br /&gt;
: &lt;br /&gt;
: Next 3 lines:&lt;br /&gt;
: &lt;br /&gt;
:  Scanner scan = new Scanner (System.in); // declaration of scanner class.&lt;br /&gt;
: &lt;br /&gt;
: System.out.print ("Enter the number of seconds: ");&lt;br /&gt;
: timeInSeconds = scan.next();&lt;br /&gt;
: &lt;br /&gt;
: This is fine, but timeInSeconds overwrites what was done earlier. If the line right after the declaration and initialization actually did anything, that work would be wiped out here.&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: hours = timeInSeconds / 3600;//no problem here use this line to fix the next line&lt;br /&gt;
: &lt;br /&gt;
: timeInSeconds += minutes * 60;//not quite&lt;br /&gt;
: &lt;br /&gt;
: The above line is equivalent to timeInSeconds = timeInSeconds + minutes * 60. Assuming that the user entered 30, it would be timeInSeconds = 30 + 0 *60. Which is 30, exactly what was entered by the user and not what you need. In short this does nothing.&lt;br /&gt;
:  &lt;br /&gt;
: Presumably you want to convert seconds into minutes. Rethink the arithmetic using the way you got hours as a guide.&lt;br /&gt;
: &lt;br /&gt;
: timeInSeconds += seconds;//this is pointless&lt;br /&gt;
: &lt;br /&gt;
: The way you have the program written this is timeInSeconds = timeInSeconds + seconds. seconds is set to 0. So it changes the value to the exact value it was. You really do not need a seconds variable since timeInSeconds will be equivalent.&lt;br /&gt;
: &lt;br /&gt;
:  System.out.println(hours + " hours: ");//this is fine&lt;br /&gt;
: System.out.println( + minutes + " minutes: ");//This might cause a compiler error&lt;br /&gt;
: System.out.println( + seconds + " seconds");//ditto, instead of using seconds, just use timeInSeconds.&lt;br /&gt;
: &lt;br /&gt;
: I am not sure if the compiler will complain about the last 2 lines. + is the concatenation operator, it is a binary operator, meaning it uses 2 operands. + minutes is only one operand, lose the first + on the last 2 lines. Even if it does compile, ditch the first + on those lines.&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: Like I said before tracing the code on paper is extremely helpful. If you would have spent 10 minutes doing this you likely would have figured out the semantic and syntax errors on your own. &lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: &lt;em&gt;&lt;span style="color: Blue;"&gt;Just my 2 bits&lt;/span&gt;&lt;em&gt;&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
Ok, Thanks man. I appreciate your help alot. As just the slightest little bit of help, can goo a long way in JAVA.&lt;br /&gt;
&lt;br /&gt;
Only problem is I think I do need a seconds variable don't I?&lt;br /&gt;
I mean if I'm asked to have a seconds amount.&lt;br /&gt;
Hours:&lt;br /&gt;
Minutes:&lt;br /&gt;
Seconds:&lt;br /&gt;
&lt;br /&gt;
Right now it will convert the hours, convert the minutes... but won't seem to convert the seconds.&lt;br /&gt;
&lt;br /&gt;
And your saying I dont need a seconds variable?&lt;br /&gt;
Why is this man?&lt;br /&gt;
&lt;/em&gt;&lt;/em&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java/316213/316256/re-converting-seconds-into-minutes-hours-and-seconds-helppartii/#316256</guid>
      <pubDate>Sun, 25 Sep 2005 08:46:34 -0700</pubDate>
      <category>Java</category>
    </item>
    <item>
      <title>Re: Converting Seconds into Minutes, Hours and Seconds... HELP!(PartII</title>
      <link>http://www.programmersheaven.com/mb/java/316213/316259/re-converting-seconds-into-minutes-hours-and-seconds-helppartii/#316259</link>
      <description>: : &lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by Vilanye at  2005-9-25 0:58:5&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
: : Lets walk through your program:&lt;br /&gt;
: : &lt;br /&gt;
: : int minutes, hours, seconds, timeInSeconds = 0; &lt;br /&gt;
: : &lt;br /&gt;
: : The reason you are getting the errors that minutes, hours and seconds might not have been initialized is because only timeInSeconds was initialized to 0. You have to explicitly initialize each one&lt;br /&gt;
: : &lt;br /&gt;
: : int minutes=0, hours=0, seconds=0, timeInSeconds = 0;//this will fix the compiler errors.&lt;br /&gt;
: : &lt;br /&gt;
: : From here on, I will assume that the corrected line above is part of your program. This will help point out your logic errors. If you had used minutes and seconds the way it should have been, the compiler would not have cared if they were initialized. It only cares when you try to use them uninitialized. &lt;br /&gt;
: : &lt;br /&gt;
: : What is the point of this next line?&lt;br /&gt;
: : &lt;br /&gt;
: : timeInSeconds = timeInSeconds - (hours * 3600);&lt;br /&gt;
: : &lt;br /&gt;
: : At this point timeInSeconds and hours are both 0. 0-(0*3600) is 0. This does nothing. What are you trying to accomplish here?&lt;br /&gt;
: : &lt;br /&gt;
: : Next 3 lines:&lt;br /&gt;
: : &lt;br /&gt;
: :  Scanner scan = new Scanner (System.in); // declaration of scanner class.&lt;br /&gt;
: : &lt;br /&gt;
: : System.out.print ("Enter the number of seconds: ");&lt;br /&gt;
: : timeInSeconds = scan.next();&lt;br /&gt;
: : &lt;br /&gt;
: : This is fine, but timeInSeconds overwrites what was done earlier. If the line right after the declaration and initialization actually did anything, that work would be wiped out here.&lt;br /&gt;
: : &lt;br /&gt;
: : &lt;br /&gt;
: : hours = timeInSeconds / 3600;//no problem here use this line to fix the next line&lt;br /&gt;
: : &lt;br /&gt;
: : timeInSeconds += minutes * 60;//not quite&lt;br /&gt;
: : &lt;br /&gt;
: : The above line is equivalent to timeInSeconds = timeInSeconds + minutes * 60. Assuming that the user entered 30, it would be timeInSeconds = 30 + 0 *60. Which is 30, exactly what was entered by the user and not what you need. In short this does nothing.&lt;br /&gt;
: :  &lt;br /&gt;
: : Presumably you want to convert seconds into minutes. Rethink the arithmetic using the way you got hours as a guide.&lt;br /&gt;
: : &lt;br /&gt;
: : timeInSeconds += seconds;//this is pointless&lt;br /&gt;
: : &lt;br /&gt;
: : The way you have the program written this is timeInSeconds = timeInSeconds + seconds. seconds is set to 0. So it changes the value to the exact value it was. You really do not need a seconds variable since timeInSeconds will be equivalent.&lt;br /&gt;
: : &lt;br /&gt;
: :  System.out.println(hours + " hours: ");//this is fine&lt;br /&gt;
: : System.out.println( + minutes + " minutes: ");//This might cause a compiler error&lt;br /&gt;
: : System.out.println( + seconds + " seconds");//ditto, instead of using seconds, just use timeInSeconds.&lt;br /&gt;
: : &lt;br /&gt;
: : I am not sure if the compiler will complain about the last 2 lines. + is the concatenation operator, it is a binary operator, meaning it uses 2 operands. + minutes is only one operand, lose the first + on the last 2 lines. Even if it does compile, ditch the first + on those lines.&lt;br /&gt;
: : &lt;br /&gt;
: : &lt;br /&gt;
: : Like I said before tracing the code on paper is extremely helpful. If you would have spent 10 minutes doing this you likely would have figured out the semantic and syntax errors on your own. &lt;br /&gt;
: : &lt;br /&gt;
: : &lt;br /&gt;
: : &lt;em&gt;&lt;span style="color: Blue;"&gt;Just my 2 bits&lt;/span&gt;&lt;em&gt;&lt;br /&gt;
: : &lt;br /&gt;
: : &lt;br /&gt;
: : &lt;br /&gt;
: : &lt;br /&gt;
: Ok, Thanks man. I appreciate your help alot. As just the slightest little bit of help, can goo a long way in JAVA.&lt;br /&gt;
: &lt;br /&gt;
: Only problem is I think I do need a seconds variable don't I?&lt;br /&gt;
: I mean if I'm asked to have a seconds amount.&lt;br /&gt;
: Hours:&lt;br /&gt;
: Minutes:&lt;br /&gt;
: Seconds:&lt;br /&gt;
: &lt;br /&gt;
: Right now it will convert the hours, convert the minutes... but won't seem to convert the seconds.&lt;br /&gt;
: &lt;br /&gt;
: And your saying I dont need a seconds variable?&lt;br /&gt;
: Why is this man?&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you are asked to use a seconds variable, then use one. You don't need it, because timeInSeconds is exactly the same as seconds.&lt;br /&gt;
&lt;br /&gt;
System.out.print ("Enter the number of seconds: ");&lt;br /&gt;
timeInSeconds = scan.next();&lt;br /&gt;
&lt;br /&gt;
You ask for the number of seconds. What does converting timeInSeconds to seconds accomplish? But if it is part of the program requirements, then you have little choice.&lt;br /&gt;
&lt;em&gt;&lt;span style="color: Blue;"&gt;Just my 2 bits&lt;/span&gt;&lt;em&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/em&gt;&lt;/em&gt;&lt;/em&gt;&lt;/em&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java/316213/316259/re-converting-seconds-into-minutes-hours-and-seconds-helppartii/#316259</guid>
      <pubDate>Sun, 25 Sep 2005 10:00:06 -0700</pubDate>
      <category>Java</category>
    </item>
    <item>
      <title>Re: Converting Seconds into Minutes, Hours and Seconds... HELP!(PartII</title>
      <link>http://www.programmersheaven.com/mb/java/316213/316261/re-converting-seconds-into-minutes-hours-and-seconds-helppartii/#316261</link>
      <description>: : : &lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by Vilanye at  2005-9-25 0:58:5&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
: : : Lets walk through your program:&lt;br /&gt;
: : : &lt;br /&gt;
: : : int minutes, hours, seconds, timeInSeconds = 0; &lt;br /&gt;
: : : &lt;br /&gt;
: : : The reason you are getting the errors that minutes, hours and seconds might not have been initialized is because only timeInSeconds was initialized to 0. You have to explicitly initialize each one&lt;br /&gt;
: : : &lt;br /&gt;
: : : int minutes=0, hours=0, seconds=0, timeInSeconds = 0;//this will fix the compiler errors.&lt;br /&gt;
: : : &lt;br /&gt;
: : : From here on, I will assume that the corrected line above is part of your program. This will help point out your logic errors. If you had used minutes and seconds the way it should have been, the compiler would not have cared if they were initialized. It only cares when you try to use them uninitialized. &lt;br /&gt;
: : : &lt;br /&gt;
: : : What is the point of this next line?&lt;br /&gt;
: : : &lt;br /&gt;
: : : timeInSeconds = timeInSeconds - (hours * 3600);&lt;br /&gt;
: : : &lt;br /&gt;
: : : At this point timeInSeconds and hours are both 0. 0-(0*3600) is 0. This does nothing. What are you trying to accomplish here?&lt;br /&gt;
: : : &lt;br /&gt;
: : : Next 3 lines:&lt;br /&gt;
: : : &lt;br /&gt;
: : :  Scanner scan = new Scanner (System.in); // declaration of scanner class.&lt;br /&gt;
: : : &lt;br /&gt;
: : : System.out.print ("Enter the number of seconds: ");&lt;br /&gt;
: : : timeInSeconds = scan.next();&lt;br /&gt;
: : : &lt;br /&gt;
: : : This is fine, but timeInSeconds overwrites what was done earlier. If the line right after the declaration and initialization actually did anything, that work would be wiped out here.&lt;br /&gt;
: : : &lt;br /&gt;
: : : &lt;br /&gt;
: : : hours = timeInSeconds / 3600;//no problem here use this line to fix the next line&lt;br /&gt;
: : : &lt;br /&gt;
: : : timeInSeconds += minutes * 60;//not quite&lt;br /&gt;
: : : &lt;br /&gt;
: : : The above line is equivalent to timeInSeconds = timeInSeconds + minutes * 60. Assuming that the user entered 30, it would be timeInSeconds = 30 + 0 *60. Which is 30, exactly what was entered by the user and not what you need. In short this does nothing.&lt;br /&gt;
: : :  &lt;br /&gt;
: : : Presumably you want to convert seconds into minutes. Rethink the arithmetic using the way you got hours as a guide.&lt;br /&gt;
: : : &lt;br /&gt;
: : : timeInSeconds += seconds;//this is pointless&lt;br /&gt;
: : : &lt;br /&gt;
: : : The way you have the program written this is timeInSeconds = timeInSeconds + seconds. seconds is set to 0. So it changes the value to the exact value it was. You really do not need a seconds variable since timeInSeconds will be equivalent.&lt;br /&gt;
: : : &lt;br /&gt;
: : :  System.out.println(hours + " hours: ");//this is fine&lt;br /&gt;
: : : System.out.println( + minutes + " minutes: ");//This might cause a compiler error&lt;br /&gt;
: : : System.out.println( + seconds + " seconds");//ditto, instead of using seconds, just use timeInSeconds.&lt;br /&gt;
: : : &lt;br /&gt;
: : : I am not sure if the compiler will complain about the last 2 lines. + is the concatenation operator, it is a binary operator, meaning it uses 2 operands. + minutes is only one operand, lose the first + on the last 2 lines. Even if it does compile, ditch the first + on those lines.&lt;br /&gt;
: : : &lt;br /&gt;
: : : &lt;br /&gt;
: : : Like I said before tracing the code on paper is extremely helpful. If you would have spent 10 minutes doing this you likely would have figured out the semantic and syntax errors on your own. &lt;br /&gt;
: : : &lt;br /&gt;
: : : &lt;br /&gt;
: : : &lt;em&gt;&lt;span style="color: Blue;"&gt;Just my 2 bits&lt;/span&gt;&lt;em&gt;&lt;br /&gt;
: : : &lt;br /&gt;
: : : &lt;br /&gt;
: : : &lt;br /&gt;
: : : &lt;br /&gt;
: : Ok, Thanks man. I appreciate your help alot. As just the slightest little bit of help, can goo a long way in JAVA.&lt;br /&gt;
: : &lt;br /&gt;
: : Only problem is I think I do need a seconds variable don't I?&lt;br /&gt;
: : I mean if I'm asked to have a seconds amount.&lt;br /&gt;
: : Hours:&lt;br /&gt;
: : Minutes:&lt;br /&gt;
: : Seconds:&lt;br /&gt;
: : &lt;br /&gt;
: : Right now it will convert the hours, convert the minutes... but won't seem to convert the seconds.&lt;br /&gt;
: : &lt;br /&gt;
: : And your saying I dont need a seconds variable?&lt;br /&gt;
: : Why is this man?&lt;br /&gt;
: : &lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: If you are asked to use a seconds variable, then use one. You don't need it, because timeInSeconds is exactly the same as seconds.&lt;br /&gt;
: &lt;br /&gt;
: System.out.print ("Enter the number of seconds: ");&lt;br /&gt;
: timeInSeconds = scan.next();&lt;br /&gt;
: &lt;br /&gt;
: You ask for the number of seconds. What does converting timeInSeconds to seconds accomplish? But if it is part of the program requirements, then you have little choice.&lt;br /&gt;
: &lt;em&gt;&lt;span style="color: Blue;"&gt;Just my 2 bits&lt;/span&gt;&lt;em&gt;&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
Well I need to get an answer with the remaining seconds.&lt;br /&gt;
Like for example:&lt;br /&gt;
Enter the number of seconds: 9999&lt;br /&gt;
&lt;br /&gt;
Hours: 2&lt;br /&gt;
Minutes: 46&lt;br /&gt;
Seconds: 39&lt;br /&gt;
&lt;br /&gt;
I do need the seconds.. I think!?&lt;br /&gt;
&lt;br /&gt;
Right now my only problem is getting those remaining seconds.&lt;br /&gt;
&lt;br /&gt;
Right now its just converting the hours.. and then the minutes, like it is doing the individual calculations. Like 9999/ 3600.. for hours.. and then doing 9999/ 60. And the seconds just keep equaling the number I typed in. This is not what I want at all. I want it to cary over the previous number.&lt;br /&gt;
&lt;br /&gt;
 I'm totally confused now...&lt;br /&gt;
&lt;/em&gt;&lt;/em&gt;&lt;/em&gt;&lt;/em&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java/316213/316261/re-converting-seconds-into-minutes-hours-and-seconds-helppartii/#316261</guid>
      <pubDate>Sun, 25 Sep 2005 10:41:52 -0700</pubDate>
      <category>Java</category>
    </item>
    <item>
      <title>Re: Converting Seconds into Minutes, Hours and Seconds... HELP!(PartII</title>
      <link>http://www.programmersheaven.com/mb/java/316213/316266/re-converting-seconds-into-minutes-hours-and-seconds-helppartii/#316266</link>
      <description>&lt;br /&gt;
: Well I need to get an answer with the remaining seconds.&lt;br /&gt;
: Like for example:&lt;br /&gt;
: Enter the number of seconds: 9999&lt;br /&gt;
: &lt;br /&gt;
: Hours: 2&lt;br /&gt;
: Minutes: 46&lt;br /&gt;
: Seconds: 39&lt;br /&gt;
: &lt;br /&gt;
: I do need the seconds.. I think!?&lt;br /&gt;
: &lt;br /&gt;
: Right now my only problem is getting those remaining seconds.&lt;br /&gt;
: &lt;br /&gt;
: Right now its just converting the hours.. and then the minutes, like it is doing the individual calculations. Like 9999/ 3600.. for hours.. and then doing 9999/ 60. And the seconds just keep equaling the number I typed in. This is not what I want at all. I want it to cary over the previous number.&lt;br /&gt;
: &lt;br /&gt;
:  I'm totally confused now...&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
ok, I understand now. Sorry about confusing you more. Yes you need seconds. Your problem is a simple arithmetic one.&lt;br /&gt;
&lt;br /&gt;
So to clarify, what you want is if the user entered 7500 seconds, you want to output 2 hours 5 minutes and 0 seconds, right?&lt;br /&gt;
&lt;br /&gt;
What you need to do is after calculating how many hours, is subtract the number of seconds in the amount of hours, and store it in time in seconds. Then use the new value to figure out minutes, subtract the number of seconds in the amount of minutes, and store that in timeInSeconds. At this point, the value in timeInSeconds is equal to seconds.&lt;br /&gt;
&lt;br /&gt;
What you were doing, and where I got confused was getting hours and minutes from the same value, not what you need presumably. So with 7500 seconds you would get 2 hours and 125 minutes.&lt;br /&gt;
&lt;br /&gt;
Here is a little bit of the code &lt;br /&gt;
&lt;br /&gt;
hours = timeInSeconds/3600;&lt;br /&gt;
timeInSeconds = timeInSeconds -(hours*3600);&lt;br /&gt;
//get minutes next using the same steps, but different values of course&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
If 7500 was entered, hours would hold 2.&lt;br /&gt;
The next line would assign 300 to timeInSeconds.&lt;br /&gt;
&lt;br /&gt;
If this looked remarkably similar to what you had earlier, you are correct. I misunderstood what you were doing, and made life harder on you. I apologize.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java/316213/316266/re-converting-seconds-into-minutes-hours-and-seconds-helppartii/#316266</guid>
      <pubDate>Sun, 25 Sep 2005 11:55:37 -0700</pubDate>
      <category>Java</category>
    </item>
    <item>
      <title>Re: Converting Seconds into Minutes, Hours and Seconds... HELP!(PartII</title>
      <link>http://www.programmersheaven.com/mb/java/316213/316268/re-converting-seconds-into-minutes-hours-and-seconds-helppartii/#316268</link>
      <description>: : : : &lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by Vilanye at  2005-9-25 0:58:5&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
: : : : Lets walk through your program:&lt;br /&gt;
: : : : &lt;br /&gt;
: : : : int minutes, hours, seconds, timeInSeconds = 0; &lt;br /&gt;
: : : : &lt;br /&gt;
: : : : The reason you are getting the errors that minutes, hours and seconds might not have been initialized is because only timeInSeconds was initialized to 0. You have to explicitly initialize each one&lt;br /&gt;
: : : : &lt;br /&gt;
: : : : int minutes=0, hours=0, seconds=0, timeInSeconds = 0;//this will fix the compiler errors.&lt;br /&gt;
: : : : &lt;br /&gt;
: : : : From here on, I will assume that the corrected line above is part of your program. This will help point out your logic errors. If you had used minutes and seconds the way it should have been, the compiler would not have cared if they were initialized. It only cares when you try to use them uninitialized. &lt;br /&gt;
: : : : &lt;br /&gt;
: : : : What is the point of this next line?&lt;br /&gt;
: : : : &lt;br /&gt;
: : : : timeInSeconds = timeInSeconds - (hours * 3600);&lt;br /&gt;
: : : : &lt;br /&gt;
: : : : At this point timeInSeconds and hours are both 0. 0-(0*3600) is 0. This does nothing. What are you trying to accomplish here?&lt;br /&gt;
: : : : &lt;br /&gt;
: : : : Next 3 lines:&lt;br /&gt;
: : : : &lt;br /&gt;
: : : :  Scanner scan = new Scanner (System.in); // declaration of scanner class.&lt;br /&gt;
: : : : &lt;br /&gt;
: : : : System.out.print ("Enter the number of seconds: ");&lt;br /&gt;
: : : : timeInSeconds = scan.next();&lt;br /&gt;
: : : : &lt;br /&gt;
: : : : This is fine, but timeInSeconds overwrites what was done earlier. If the line right after the declaration and initialization actually did anything, that work would be wiped out here.&lt;br /&gt;
: : : : &lt;br /&gt;
: : : : &lt;br /&gt;
: : : : hours = timeInSeconds / 3600;//no problem here use this line to fix the next line&lt;br /&gt;
: : : : &lt;br /&gt;
: : : : timeInSeconds += minutes * 60;//not quite&lt;br /&gt;
: : : : &lt;br /&gt;
: : : : The above line is equivalent to timeInSeconds = timeInSeconds + minutes * 60. Assuming that the user entered 30, it would be timeInSeconds = 30 + 0 *60. Which is 30, exactly what was entered by the user and not what you need. In short this does nothing.&lt;br /&gt;
: : : :  &lt;br /&gt;
: : : : Presumably you want to convert seconds into minutes. Rethink the arithmetic using the way you got hours as a guide.&lt;br /&gt;
: : : : &lt;br /&gt;
: : : : timeInSeconds += seconds;//this is pointless&lt;br /&gt;
: : : : &lt;br /&gt;
: : : : The way you have the program written this is timeInSeconds = timeInSeconds + seconds. seconds is set to 0. So it changes the value to the exact value it was. You really do not need a seconds variable since timeInSeconds will be equivalent.&lt;br /&gt;
: : : : &lt;br /&gt;
: : : :  System.out.println(hours + " hours: ");//this is fine&lt;br /&gt;
: : : : System.out.println( + minutes + " minutes: ");//This might cause a compiler error&lt;br /&gt;
: : : : System.out.println( + seconds + " seconds");//ditto, instead of using seconds, just use timeInSeconds.&lt;br /&gt;
: : : : &lt;br /&gt;
: : : : I am not sure if the compiler will complain about the last 2 lines. + is the concatenation operator, it is a binary operator, meaning it uses 2 operands. + minutes is only one operand, lose the first + on the last 2 lines. Even if it does compile, ditch the first + on those lines.&lt;br /&gt;
: : : : &lt;br /&gt;
: : : : &lt;br /&gt;
: : : : Like I said before tracing the code on paper is extremely helpful. If you would have spent 10 minutes doing this you likely would have figured out the semantic and syntax errors on your own. &lt;br /&gt;
: : : : &lt;br /&gt;
: : : : &lt;br /&gt;
: : : : &lt;em&gt;&lt;span style="color: Blue;"&gt;Just my 2 bits&lt;/span&gt;&lt;em&gt;&lt;br /&gt;
: : : : &lt;br /&gt;
: : : : &lt;br /&gt;
: : : : &lt;br /&gt;
: : : : &lt;br /&gt;
: : : Ok, Thanks man. I appreciate your help alot. As just the slightest little bit of help, can goo a long way in JAVA.&lt;br /&gt;
: : : &lt;br /&gt;
: : : Only problem is I think I do need a seconds variable don't I?&lt;br /&gt;
: : : I mean if I'm asked to have a seconds amount.&lt;br /&gt;
: : : Hours:&lt;br /&gt;
: : : Minutes:&lt;br /&gt;
: : : Seconds:&lt;br /&gt;
: : : &lt;br /&gt;
: : : Right now it will convert the hours, convert the minutes... but won't seem to convert the seconds.&lt;br /&gt;
: : : &lt;br /&gt;
: : : And your saying I dont need a seconds variable?&lt;br /&gt;
: : : Why is this man?&lt;br /&gt;
: : : &lt;br /&gt;
: : &lt;br /&gt;
: : &lt;br /&gt;
: : If you are asked to use a seconds variable, then use one. You don't need it, because timeInSeconds is exactly the same as seconds.&lt;br /&gt;
: : &lt;br /&gt;
: : System.out.print ("Enter the number of seconds: ");&lt;br /&gt;
: : timeInSeconds = scan.next();&lt;br /&gt;
: : &lt;br /&gt;
: : You ask for the number of seconds. What does converting timeInSeconds to seconds accomplish? But if it is part of the program requirements, then you have little choice.&lt;br /&gt;
: : &lt;em&gt;&lt;span style="color: Blue;"&gt;Just my 2 bits&lt;/span&gt;&lt;em&gt;&lt;br /&gt;
: : &lt;br /&gt;
: : &lt;br /&gt;
: Well I need to get an answer with the remaining seconds.&lt;br /&gt;
: Like for example:&lt;br /&gt;
: Enter the number of seconds: 9999&lt;br /&gt;
: &lt;br /&gt;
: Hours: 2&lt;br /&gt;
: Minutes: 46&lt;br /&gt;
: Seconds: 39&lt;br /&gt;
: &lt;br /&gt;
: I do need the seconds.. I think!?&lt;br /&gt;
: &lt;br /&gt;
: Right now my only problem is getting those remaining seconds.&lt;br /&gt;
: &lt;br /&gt;
: Right now its just converting the hours.. and then the minutes, like it is doing the individual calculations. Like 9999/ 3600.. for hours.. and then doing 9999/ 60. And the seconds just keep equaling the number I typed in. This is not what I want at all. I want it to cary over the previous number.&lt;br /&gt;
: &lt;br /&gt;
:  I'm totally confused now...&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
I'm not in the mood of real coding right now ,so I'll write some pseudo code:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
inputsecs = 9999
secs = 0
mins = 0
hours = 0

//Now we need to add 3600 until it exceeds inputsecs(9999)
add_3600_again:
if secs + 3600 &amp;gt; inputsecs then goto hours_done
hours = hours + 1
secs = secs + 3600
goto add_3600_again
hours_done:
//hours = 2

inputsecs = inputsecs - hours * 3600 //9999 - 7200 = 2799

//Now we need to add 60 until it exceeds inputsecs(2799)

secs = 0
add_60_again:
if secs + 60 &amp;gt; inputsecs then goto mins_done
secs = secs + 60
mins = mins + 1
goto add_60_again
mins_done:
//mins = 46

inputsecs = inputsecs - mins * 60 //2799 - 2760 = 39

//and its done!
hours = 2
mins = 46
inputsecs = 39
&lt;/pre&gt;&lt;br /&gt;
Im sure that if you look at the code with an open mind, you'll understand my method. Good luck!&lt;br /&gt;
&lt;/em&gt;&lt;/em&gt;&lt;/em&gt;&lt;/em&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java/316213/316268/re-converting-seconds-into-minutes-hours-and-seconds-helppartii/#316268</guid>
      <pubDate>Sun, 25 Sep 2005 12:26:26 -0700</pubDate>
      <category>Java</category>
    </item>
  </channel>
</rss>