JS Reverse in java

JS Reverse in java

Given a number, you task is to reverse its digits. If the reversed number contains 0s in the beginning, you must remove them as well.

Input Format

Functional problem, Number is the input

Output Format

Output is a single line containing reversed number n.

Example 1

Input

123445

Output

 544321

Explanation

reverse of 123445 is 544321

Constraints:

1<=size of n<=100000

Solution of JS Reverse in java:–

const rl = require('readline')
 

 const reader = rl.createInterface({
  input: process.stdin,
  output: process.stdout
 })
 

 reader.on('line', (line) => {
 
 const n=parseInt(line);
 console.log(JsReverse(n));
 
 
 })

function JsReverse(n)
{
     let x = n.toString();
    let y = '';

    for(let i of x) {
        y = i + y
    }
    return parseInt(y) * Math.sign(n);
}

Add a Comment

Your email address will not be published. Required fields are marked *