Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)

Can anyone help me how I can able to get the inputs and outputs in Hackerrank and Hackerearth with an example using a JavaScript?

function processData(input) {

//Enter your code here

process.stdin.resume();

process.stdin.setEncoding("ascii");

_input = "";

process.stdin.on("data", function (input) {

  _input += input;

});

process.stdin.on("end", function () {

  processData(_input);

});

1 Answer

0 votes
by (26.7k points)

You need to do something like this for the solution:

function main(input) {

    //Enter your code here

    var num = parseInt(input, 10);//This line expects input to be a string so convert to an int as per problem

    var res=1;

    for(var i=num;i>1;i--) {

        res *= i; 

    }

    process.stdout.write(res);//This is how you write output.

I hope this will help.

Want to become a Java Expert? Join Java Course now!!

Want to know more about Java? Watch this tutorial on Java Tutorial for Beginners | Java Programming:

Related questions

0 votes
1 answer
0 votes
1 answer
asked Apr 13, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer
0 votes
4 answers
asked Mar 31, 2021 in Python by laddulakshana (16.4k points)

Browse Categories

...