Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • DSA
  • Practice Problems
  • Python
  • C
  • C++
  • Java
  • Courses
  • Machine Learning
  • DevOps
  • Web Development
  • System Design
  • Aptitude
  • Projects
Open In App
Next Article:
How to read and write JSON files in Scala?
Next article icon

Scala Console | println, printf and readLine

Last Updated : 28 Nov, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Console implements functions for displaying the stated values on the terminal i.e, with print, println, and printf we can post to the display. It is also utilized in reading values from the Console with the function from scala.io.StdIn. It is even helpful in constructing interactive programs. Let's discuss it in detail and also lets see some examples related to it.

  • println: It is utilized in putting down values to the Console and moreover computes a trailing newline. we can pass any types as argument to it.
  • Print: It is equivalent to println but it does not computes any trailing line. It puts down the data to the beginning of the line.
  • printf: This is helpful in writing format strings and also places extra arguments. Example: 
Scala
// Scala program of print // functions  // Creating an object object GfG {      // Main method     def main(args: Array[String])      {          // Applying console with println         Console.println("GeeksforGeeks")          // Displays output with no         // trailing lines         print("CS")         print("_portal")          // Used for a newline         println()          // Displays format string         printf("Age = %d", 24)     } } 
Output:
GeeksfoGeeks CS_portal Age = 24
  • The println and Console.println both are equivalent.
  • readLine(): It is a method in which user gives inputs in the pattern of String from the keyboard. Example: 
Scala
// Scala program of readLine() // method  // Creating an object object GfG  { // Main method def main(args: Array[String])   { // Applying a loop while (true) {      // Reads the line from the Console     val result = scala.io.StdIn.readLine()      // Displays the string that is      // given by the user     printf("Enter the String: %s", result)        //prints newline     println()      }    } } 
Output:
//giving user defined inputs GfG  //output by readline Enter the String: Gfg  //again giving inputs Nidhi  //output Enter the String: Nidhi 
  • Here, the while loop is infinite in nature and after giving user inputs the variable will contains that (GfG) string and if again we given any input then the variable will contain that (Nidhi) input.

Next Article
How to read and write JSON files in Scala?
author
nidhi1352singh
Improve
Article Tags :
  • Scala
  • Scala
  • Scala-Basics

Similar Reads

  • How to Print RDD in scala?
    Scala stands for scalable language. It was developed in 2003 by Martin Odersky. It is an object-oriented language that provides support for functional programming approach as well. Everything in scala is an object e.g. - values like 1,2 can invoke functions like toString(). Scala is a statically typ
    4 min read
  • How to Read and Write CSV File in Scala?
    Data processing and analysis in Scala mostly require dealing with CSV (Comma Separated Values) files. CSV is a simple file format used to store tabular data, such as a spreadsheet or database. Each line of a CSV file is plain text, representing a data row, with values separated by commas (,). Readin
    5 min read
  • Command Line Argument in Scala
    The arguments which are passed by the user or programmer to the main() method are termed as Command-Line Arguments. main() method is the entry point of execution of a program. main() method accepts an array of strings. runtime. But it never accepts parameters from any other method in the program. Sy
    2 min read
  • Scala Double >=(x: Int) method
    In Scala, Double is a 64-bit floating point number, which is equivalent to Java’s double primitive type. The >=(x: Int) method is utilized to return true if this value is greater than or equal to x, false otherwise. Method Definition - def >=(x: Int): Boolean Returns - Returns true if this val
    1 min read
  • How to read and write JSON files in Scala?
    Scala is frequently used for reading and writing JSON files in a variety of applications, particularly it includes data transmission. Table of Content Steps for reading JSON files in Scala:Steps for writing JSON files in Scala:Steps for reading JSON files in Scala:When reading JSON files in Scala we
    3 min read
  • How to Install Scala in Linux?
    Prerequisite: Introduction to Scala Before, we start with the process of Installing Scala on our System. We must have first-hand knowledge of What the Scala Language is and what it actually does? Scala is a general-purpose, high-level, multi-paradigm programming language. It is a pure object-oriente
    3 min read
  • Pure Function In Scala
    In any programming language, there are two types of functions: 1. PURE FUNCTIONS 2. IMPURE FUNCTIONSThere is a basic difference between the two, that is pure function doesn’t change the variable it’s passed and an impure function does. For example, there exists a function which increases the input b
    3 min read
  • Continuations in Scala
    The main idea of continuations in scala is the ability to interrupt a program, save its control state, and resume it at a later point in time. Continuations pop up on the web as a concept that could help with event-based programming. Continuations, and in particular delimited continuations, are a ve
    3 min read
  • Program to print Java List in Scala
    A java list can be returned from a Scala program by writing a user defined method of Java in Scala. Here, we don't even need to import any Scala’s JavaConversions object in order to make this conversions work. Now, lets see some examples. Example:1# C/C++ Code // Scala program to print Java List //
    2 min read
  • Scala and Java Interoperability
    Java is one of the top programming languages and the JVM (Java Virtual Machine) facility makes it easier to develop in it. But there are small tweaks and features in Java, so developers search for different options like Scala. Scala and Java interoperability means that a code written in one can be e
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences