This is a Java Program to Perform String Concatenation.
Enter any two strings as input. We have made a function into which we pass the two given strings and this function uses concatenation operator for string concatenation and hence return the desired string back to the main function.
Here is the source code of the Java Program to Perform String Concatenation. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
import java.util.Scanner;
public class String_Concatenate
{
public static void main(String[] args)
{
String a, b, c;
Scanner s = new Scanner(System.in);
System.out.print("Enter first string:");
a = s.nextLine();
System.out.print("Enter second string:");
b = s.nextLine();
String_Concatenate obj = new String_Concatenate();
c = obj.concat(a, b);
System.out.println("New String:"+c);
}
String concat(String x, String y)
{
String z;
z = x + " " + y;
return z;
}
}
Output:
$ javac String_Concatenate.java $ java String_Concatenate Enter first string:hello Enter second string:world New String:hello world
Sanfoundry Global Education & Learning Series – 1000 Java Programs.
advertisement
advertisement
Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.
Related Posts:
- Check Programming Books
- Apply for Java Internship
- Practice BCA MCQs
- Practice Programming MCQs
- Check Java Books