Go Back   Java Programming Forums > Java Standard Edition Programming Help > Java Theory & Questions


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 13-09-2009, 08:42 PM
Junior Member
 

Join Date: Sep 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
CYKO is on a distinguished road
Default A program that reads in secounds, and prints out hours minutes

Hi, im new to Java and just testing something out. (Sorry for my bad english)

How do i make a java application where the user input secounds, and the program "transforms" these secounds into hours, minutes and secounds.

Like this:

11873

--> 3 hours, 17 minutes, 53 secounds.

Anyone got a suggestion with some simple code?(so i can understand it )
I cant find a way to do it.



Reply With Quote Share this thread on Facebook
Sponsored Links
Java Training from DevelopIntelligence
  #2 (permalink)  
Old 14-09-2009, 03:42 AM
helloworld922's Avatar
Super Moderator
 

Join Date: Jun 2009
Posts: 1,347
Thanks: 5
Thanked 285 Times in 257 Posts
helloworld922 will become famous soon enoughhelloworld922 will become famous soon enoughhelloworld922 will become famous soon enough
Default Re: A program that reads in secounds, and prints out hours minutes

hmm.. ok. I won't give you the exact code, but i'll give you hints.

there are 60 seconds in a minute, and 3600 seconds in an hour.

So, 11873/3600 should give you how many hours there are. However, because we want the hours as an integer and not some decimal, we want to make sure that we either cast to int or use the int data type.
Java Code
System.out.println("5/3 = " + 5/3); // prints out 1 because 5 and 3 are recognized as int's
System.out.println("5.0/3.0 = " 5.0/3.0); // prints out 1.666666666... because 5.0 and 3.0 are recognized as doubles
The number of hours and seconds would be the remainder of seconds left after the hours have been taken out. An easy way to get this value is by using the modulus operator. It's basically a divide operation, but instead of giving the quotient, it gives the remainder

Java Code
System.out.println("The remainder of 100/3 is " + 100%3); // should print out 1
The left-over seconds now must be split into minutes and seconds. I'll leave that up to you, but here's a hint: copy what i said above and make a few changes
__________________
ASCII a question .. Get an ANSI

Please surround your code with [highlight=Java]code goes here[/highlight].
Reply With Quote
The Following User Says Thank You to helloworld922 For This Useful Post:
Json (15-09-2009)
Reply

Thread Tools
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 On



Similar Threads
Thread Thread Starter Forum Replies Last Post
The 10 minutes “Getting started with RMI” tutorial danielstoner Java Code Snippets and Tutorials 0 08-10-2008 04:18 AM


100 most searched terms
Search Cloud
action listener in java actionlistener actionlistener in java addactionlistener addactionlister arraylist value into hash cannot find symbol method create an abstract class called shape with abstract methods+java double to integer double to integer in java double to integer java eclipse shortcut keys exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread main java.lang.outofmemoryerror java heap space in eclipse get files from folder java by threads get mouse position java how to convert list to map in java how to format double in java how to format doubles in java how to make a calculator in jframe using jcreator http://www.javaprogrammingforums.com/collections-generics/2688-grade-array-trouble.html http://www.javaprogrammingforums.com/object-oriented-programming/3713-limiting-decimal-places-double.html java actionlistener java cos java double format java double to int java format double java forum java forums java get mouse position java heap size exception java nextline() java program to find dimensions of a room java programming codes using astirisks java programming forum java programming forums java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.lang.reflect.invocationtargetexception jbutton actionlistener jtable questions in java jtext bold jtextarea font jxl.read.biff.biffexception: unable to recognize ole stream mean value decimal double java oops java assignments programmer forum smack api messagelistener transaction using gui and 2 dimensional array code in java two dimensional arraylist in java

All times are GMT. The time now is 09:32 AM.
Powered by vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.