ProAnswers.org

What java fromat alternate conversion for the hexadecimal number?

If you precede the %x format specifier with a #, the hexadecimal number will be printed with a 0x prefix.

import java.util.Formatter;

public class Main {

  public static void main(String args[]) {

    Formatter fmt = new Formatter();

    fmt.format("%#X", 1); 

    System.out.println(fmt);

  }

}

The output:

0X1