java concatenate strings
public class ConcatenationExample {
public static void main(String args[]) {
//One way of doing concatenation
String str1 = "Welcome";
str1 = str1.concat(" to ");
str1 = str1.concat(" String handling ");
System.out.println(str1);
//Other way of doing concatenation in one line
String str2 = "This";
str2 = str2.concat(" is").concat(" just a").concat(" String");
System.out.println(str2);
}
}
// CPP program to concatenate
// two integers into one
#include <iostream>
#include <string>
using namespace std;
// Function to concatenate
// two integers into one
int concat(int a, int b)
{
// Convert both the integers to string
string s1 = to_string(a);
string s2 = to_string(b);
// Concatenate both strings
string s = s1 + s2;
// Convert the concatenated string
// to integer
int c = stoi(s);
// return the formed integer
return c;
}
int main()
{
int a = 23;
int b = 43;
cout << concat(a, b) << endl;
return 0;
}
// This code is contributed by Ayush Singla(@ayusin51)