Sometimes in Competitive programming, it is essential to print the output in a given specified format. Most users are familiar with printf function in C. Let us see discuss how we can format the output in Scala. When a String contains values as well as texts succeeding it then formatting is required for changing values and adding texts enclosing it.
I have written 30 articles
- In Scala Formatting of strings can be done utilizing two methods namely format() method and formatted() method.
- These methods have been approached from the Trait named StringLike.
Format method can be utilized for format strings and you can even pass parameters to it, where %d is used for Integers and %f is used for floating-points or Doubles.
There are 15 books and cost of each book is 345.250000
Geeta is a coder.
Here, %s is used for strings and %c is used for characters.
This method can be utilized on Integer, Double as well as Strings, as it can apply on any object.
I have written 30 articles.
Here, format string is passed as an argument in the formatted method.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.