What is Readline?

Complete the code in the editor below. The variables i, d, and s are already declared and initialized for you. Input:i = 4
d = 4.0
s = 'HackerRank'
Output:
8
8.0
HackerRank is the best place to practice code!
You must:1. Declare variables: one of type int, one of type double, and one of type String.2. Read lines of input from stdin (according to the sequence given in the Input Format section below) and initialize your variables.Use the operator to perform the following operations:A. Print the sum of plus your int variable on a new line.B. Print the sum of plus your double variable to a scale of one decimal place on a new line.C. Concatenate with the string you read as input and print the result on a new line.
puts (i * 2).to_i
puts (d * 2).to_f
puts s + ' is the best place to practice code!'
Input:
i = 12
d = 4.0
s = 'HackerRank'
Your output:
8
8.0
HackerRank is the best place to practice code
Expected Output:
16
8.0
HackerRank is the best place to practice code!
Ruby:i = 4
d = 4.0
s = 'HackerRank'
i2 = readline.to_i
d2 = readline.to_f
s2 = readline.to_s
puts (i + i2).to_i
puts (i + d2).to_f
puts (s + s2).to_s
JavaScript:i = 4
d = 4.0
s = 'HackerRank'
let i2 = parseInt(readLine()) // we are in JS, must be camelcase
let d2 = parseFloat(readLine())
let s2 = readLine()
console.log(i + i2)
console.log(d + d2).toFixed(1))

// toFixed is fix point notation indicating the number of decimal places after the integer
console.log(s +s2)

--

--

--

Fullstack Software Engineer | Musician | Food Lover | Coffee Addict

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

3 ways to tackle the longest increasing subsequence problem(Golang)

K9 Mask Sees Major Boost From ‘Shark Tank’ Appearance, Company Now Looks To Expand

Migrating from IBM MQ to Amazon MQ [jms apache camel]

Tips & Tricks on How to Develop Software for Startups

Learn about the elastic Beanstalk and how to deploy node application using this service

Which course is best for Python developer?

Which course is best for Python developer?

Although every programming language has its advantages and disadvantages.

How to Automatically Generate Command-Line Interface for Python Programs

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Grace Yuiko Nakano

Grace Yuiko Nakano

Fullstack Software Engineer | Musician | Food Lover | Coffee Addict

More from Medium

“More of the Universe, more time with you”: Doctor Who’s same-sex storyline and seeing myself in…

How we ended up in the PUC project

The Jeff Bezos Meeting Method That Everyone Should Learn

From Prototype To Work of Art