EnderEgg
EnderEgg

Reputation: 335

Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = 'O'

I'm sorry if this question has been posted, but I wasn't able to find an answer.

I've been watching thenewboston tutorials on youtube for java, and now I'm getting this error:

Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = 'O'
at java.util.Formatter$FormatSpecifier.conversion(Unknown Source)
at java.util.Formatter$FormatSpecifier.<init>(Unknown Source)
at java.util.Formatter.parse(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.lang.String.format(Unknown Source)
at tuna.toMilitary(tuna.java:14)
at apples.main(apples.java:4)

I don't understand what I'm doing wrong, it's exactly as he has it (or at least I couldn't find anything different.

class apples{
public static void main (String[] args) {
    tuna tunaObject = new tuna();
    System.out.println(tunaObject.toMilitary());
}

public class tuna {
private int hour;
private int minute;
private int second;

public void setTime(int h, int m, int s){
    hour = ((h>=0 && h<24) ? h : 0);
    minute = ((m>=0 && m<60) ? m : 0);
    second = ((s>=0 && s<60) ? s : 0);

}

public String toMilitary(){
    return String.format("%O2d:%O2d:O2d", hour, minute, second );
}

Thanks a lot. (I do know one "}" is missing in each block of code)

Upvotes: 1

Views: 4190

Answers (1)

Jean Logeart
Jean Logeart

Reputation: 53829

In "%O2d:%O2d:O2d", replace O (the letter) by 0 (the number)

And as Cinnam mentionned, a % is missing.

The final format needs to be "%02d:%02d:%02d"

Upvotes: 1

Related Questions