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

The Easiest Way to Build a WordPress Form and Link it to Stripe

JetFormBuilder prices

Building a Restful API with ASP.NET Web API and SQL Server.

Working with Spring Boot and Hazelcast(Distributed Cache)

The Best Hosting Solution For WordPress Sites In 2021.

Accessibility in Web Development

Building For Vernacular: Challenges and Opportunities

eFileCabinet vs. M-Files: A Side-by-Side Comparison

Custom domain in AWS API Gateway

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

DJI Mavic 3 Review: A good step towards a cinematic future of drones

My vacation to Florida

2/24/2022

Applying the Zettelkasten Method in the Real World: