Go Back   Computer Forums > Web Design | Website Development > Web Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 09-08-2006, 01:25 PM   #1
Daemon Poster
 
burton_o6's Avatar
 
Join Date: Jan 2006
Posts: 968
Default Quick simple question

I'm in a java j++ class. And i need to write a class that basically needs to turn 197 minutes into hours and minutes. I know that this is a simple task, i just cant think of it. What i need, is the output to be 3hrs, 17 minutes but it just comes out as:
Time worked is 3.283333333333333 hours and 3.283333333333333


I know that is should look somthing like this. Thanks again.

Quote:
public class Time
{
public static void main(String[] args)
{
double Minute, Hour, Modulus;
Minute = 197;
Hour = Minute / 60;
Modulus = Hour % 60;
System.out.println ("Time worked is " + Hour);
System.out.println (" hours and " + Modulus);
}
}
Ok i found ONE problem. It should be minute % 60. But the hour still shows .283333333333333. It should show 3.
Quote:
public class Time
{
public static void main(String[] args)
{
double Minute, Hour, Modulus;
Minute = 197;
Hour = Minute / 60;
Modulus = Minute % 60;
System.out.println ("Time worked is " + Hour);
System.out.println (" hours and " + Modulus);
}
}
And just like that i figured it out. When i have a double it uses decimals. And that is why im getting the decimal for my hour. When i change it from a double to an int. It only displays whole numbers. I knew it was an easy fix but i just chouldnt think at the time.

Quote:
public class Time
{
public static void main(String[] args)
{
int Minute, Hour, Modulus;
Minute = 197;
Hour = Minute / 60;
Modulus = Minute % 60;
System.out.println ("Time worked is " + Hour);
System.out.println (" hours and " + Modulus);
}
}
__________________

burton_o6 is offline   Reply With Quote
Old 09-21-2006, 06:40 PM   #2
Baseband Member
 
Join Date: Jun 2004
Posts: 77
Send a message via Yahoo to ewomack
Default Re: Quick simple question

You got it! Watch those nasty data types.
__________________
Ed Womack
www.getmilked.com
ewomack is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 06:55 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0