Scala print println printf functions

 191 total views,  2 views today

Welcome to Scala series.In this tutorial you will learn about Scala print println printf functions

print

To print or display in same line use below print() function.

Example

def main(args: Array[String]) {
    print("Hello Scala")
    print("Hello World")
}

Output

Hello ScalaHello World

println

println() function prints the inputs in new line.

Example

def main(args: Array[String]) {
    println("Hello Scala")
    println("Hello World")
}

Output

Hello Scala
Hello World

printf

printf() function is useful in formatting strings and it prints consecutive printf calls in same line

Example

def main(args: Array[String]) {
    printf("My age is %d", 24);
  }

Output

My age is 24

Example

 def main(args: Array[String]) {
    printf("My age is %d", 24);
    printf("My age is %d %d", 24, 23);
  }

Output

My age is 24My age is 24 23

Thanks for reading. Please leave your comments and give us a thumbs up!

References : Scala Documentation

Tags :

About the Author

Rajasekar

Hey There, My name is Rajasekar and I am the author of this site. I hope you are liking my tutorials and references. Programming and learning new technologies are my passion. The ultimate idea of this site is to share my knowledge(I am still a learner :)) and help you out!. Please spread your words about us (staticreference.com) and give a thumbs up :) Feel free to contact me for any queries!.