Write a program to convert an integer into a string.
Example
Input: num=1320
Output: str="1320"
Approach
Java
public class IntToString {public static void main(String[] args) {int num = 1320;String numStr = numToString(num);System.out.println("Number String is " + numStr);}private static String numToString(int num) {return String.valueOf(num);}}
C++
#include <bits/stdc++.h>using namespace std;//function to convert the//integer to stringstring intToString(int num){//string streamstringstream str1;//put the value into strstr1 << num;//convert into string formatstring str = str1.str();return str;}int main(){int num=1320;//call the function to convert//the into stringstring str=intToString(num);// print the stringcout << str;return 0;}
No comments:
Post a Comment