Java String Format Example #2:The following example uses the flag ‘ -‘ to left-justify the Strings with the width of 30 characters ( %-30s): List listBook = Arrays.asList( It is sold at %.2f USD today.%n", title, price) Note that the %n format specified at the end of the String produces a line terminator specific to the underlying operating system.Output: Effective Java is a great book. Java String Format Example #1:The following code formats a String, an integer number and a float number with the precision of 2 numbers after the decimal point (. Now, let’s see various code examples that demonstrate the usages of format String syntax to format output.
0 Comments
Leave a Reply. |