problem: The user enters seconds the output should be days,hours,minutes,seconds format
So if user enter 86400 seconds it will be 1 day, 0 hours, 0 minutes, 0 seconds.
If User enters 86401 seconds it will be 1 days, 0 hours, 0 minutes, 1 second.
Well this is my code, and it doesn't work..
Scanner scan = new Scanner(System.in);
double userInput;
double secondsInDay = 86400;
double secondsInhours = 3600;
double secondsInMinutes = 60;
double seconds;
System.out.println("Please enter the seconds to convert to days,hours,minutes,seconds");
userInput = scan.nextDouble();
double answerDay = userInput % secondsInDay;
double answerHours = answerDay % secondsInhours;
double answerMinutes = answerHours % secondsInMinutes;
double answerSeconds = answerMinutes;
// System.out.println(""+answerDay);
// System.out.println(""+answerHours);
// System.out.println(""+answerMinutes);
// System.out.println(""+answerSeconds);
if(answerDay >= 1)
{
System.out.println("Days = "+answerDay);
}
else if(answerDay == 0)
{
System.out.println("Zero days");
}
if(answerHours >= 1)
{
System.out.println("Hours = "+answerHours);
}
else if(answerHours == 0)
{
System.out.println("Zero hours");
}
if(answerMinutes >= 1)
{
System.out.println("Minutes = "+answerMinutes);
}
else if(answerMinutes == 0)
{
System.out.println("Zero minutes");
}
if(answerSeconds >= 1)
{
System.out.println("Seconds = "+answerSeconds);
}
else if(answerSeconds == 0)
{
System.out.println("Zero seconds");
}
Loading
VulpesPosted Feb 3, 2012, 6:34 PM
int userInput;
int secondsInDay = 86400;
int secondsInhours = 3600;
int secondsInMinutes = 60;
Also, this part of the code:
double answerDay = userInput % secondsInDay;
double answerHours = answerDay % secondsInhours;
double answerMinutes = answerHours % secondsInMinutes;
double answerSeconds = answerMinutes;
should be:
int answerDay = userInput / secondsInDay;
int remainder = userInput % secondsInDay;
int answerHours = remainder / secondsInhours;
remainder = remainder % secondsInhours;
int answerMinutes = remainder / secondsInMinutes;
int answerSeconds = remainder % secondsInMinutes;
Prime bPosted Feb 7, 2012, 9:10 PM
I just found out you can use ctrl+space and it will display my declared variables , reserved words that you want to use , etc. So its not so bad, before I had to type out everything out....
Sam HobbsPosted Feb 5, 2012, 11:15 PM
Have you tried Eclipse?
VulpesPosted Feb 4, 2012, 1:53 PM
However, we've been getting a lot of questions about Java recently and there's now a dedicated forum category for it.
Although I don't use it, I thought NetBeans did have intellisense support though I'd be surprised if it was as good as VS.
Prime bPosted Feb 4, 2012, 12:20 PM
And why netbeans has such lame IDE, no intellisense, takes so much more time to type out each variable , reserved words, etc..
Prime bPosted Feb 4, 2012, 12:11 PM
VulpesPosted Feb 4, 2012, 4:54 AM
Programming is confusing enough when you're starting out and, even though the syntax of Java and C# is fairly similar, trying to learn them both simultaneously is not a good idea, IMO.
It's best to master one language before going on to learn another, otherwise you just end up with a big muddle in your head!
Prime bPosted Feb 3, 2012, 7:07 PM