Why is
public static void main(String arr[]){
System.out.println("[" + String.format("%, d",1000000000) + "]");
}
Writing it as [ 1,000,000,000]
, with a space in front of the number?
Also what does "%, d" mean as compared to "%,d" as a format specifier?
"%, d"
means that you are printing 1 space, then an integer with comma(s) ([ 1,000,000,000]
)
"%,d"
means that you are printing an integer with comma(s) ([1,000,000,000]
)
"%d"
means that you are printing an integer without comma(s) ([1000000000]
)
When you run following line
// extra space in front with number formatted
System.out.println(String.format("%, d",1000000000));
// number formatted with ,
System.out.println(String.format("%,d",1000000000));
// just number
System.out.println(String.format("%d",1000000000));
OUTPUT:
1,000,000,000
1,000,000,000
1000000000
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With