-2

as the description say's i have 3 instance variables

private int Hours;
private int Minutes;
private int Seconds;

i have already completed the part of setting and getting said values, but i am rather stuck on the part where i need to format this into the HH:MM:SS format with leading zeros for the values that are less than 0, we are assuming that we are using a scanner to allow a user to input whatever we want.

thanks!

heres the method its being done under

public String toString()
{
//dont know what to do to format it as wanted
//return "the formatted output"
}

1 Answers1

0

A few options. One would be to create an instance of LocalTime (https://docs.oracle.com/javase/8/docs/api/java/time/LocalTime.html#of-int-int-int-) and then format it (https://docs.oracle.com/javase/8/docs/api/java/time/LocalTime.html#format-java.time.format.DateTimeFormatter-)

Or you could just use String format - https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#format(java.lang.String,%20java.lang.Object...)

Chris
  • 1,644
  • 1
  • 11
  • 15