You are given an integer , you have to convert it into a string.

Please complete the partially completed code in the editor. If your code successfully converts  into a string  the code will print "Good job". Otherwise it will print "Wrong answer".

 can range between  to  inclusive.


hackerrank java int to string solution


Java Int to String problem solution | HackerRank

import java.util.*;
import java.lang.*;
import java.io.*;

class ConvertIntToString
{
    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here
        int number = -782;
        String numberAsString = Integer.toString(number);
        System.out.println(numberAsString);
    }
}

Second solution

import java.util.*;
import java.lang.*;
import java.io.*;
 
class ConvertIntToString
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		int number = -782;
		String numberAsString = String.valueOf(number);
		System.out.println(numberAsString);
	}
}

One-line code

String s=String.valueOf(n);