is it even possible to add a 0 in java with terny operators?

前端 未结 3 1003
死守一世寂寞
死守一世寂寞 2021-01-29 11:16

Hi I\'ve tried everything from terny operators, if else statements and parsing the int to a string, I am making a clock that reads 4:01 4:02 but instead it outputs 4:1

t

3条回答
  •  無奈伤痛
    2021-01-29 11:45

    Look at Java Tutorial: Formatting Numeric Print Output.

    For example:

      long n = 461012;
      System.out.format("%08d%n", n);    //  -->  "00461012"
    

    Another example:

      Calendar c = Calendar.getInstance();
      System.out.format("%tl:%tM %tp%n", c, c, c);  // -->  "2:34 am"
    

提交回复
热议问题