The Artima Developer Community
Sponsored Link

Java Answers Forum
Set length of an int.

1 reply on 1 page. Most recent reply: Nov 9, 2011 1:15 AM by Vincent O'Sullivan

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Auke de Peuter

Posts: 1
Nickname: auke88
Registered: Nov, 2011

Set length of an int. Posted: Nov 8, 2011 3:18 PM
Reply to this message Reply
Advertisement
Hi everybody, Im busy doing homework at the moment, and im stuck at a point.
I need to figure out how to give a length to an integer.
Like for a double you can set how many decimals you want (in the output) by changing %f to %.2f

Here is the problem:

out.printf("The total time is: %d:%d:%d", timeHour, timeMinutes, timeSeconds);

the output i need has to be in the form
00:00:00
so even if theres is only 1 hour 8 minutes en 53 seconds the output gives
01:08:53

im stuck at an output as: 1:8:53

Id really appreciated some help.
I hope before thursday since thats the day i have to submit the program :).
Thanks! Auke


Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: Set length of an int. Posted: Nov 9, 2011 1:15 AM
Reply to this message Reply
out.printf("The total time is: %02d:%02d:%02d", timeHour, timeMinutes, timeSeconds);

Flat View: This topic has 1 reply on 1 page
Topic: How to make multithreaded chat application Previous Topic   Next Topic Topic: delete objects;

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use