Java Program to Concatenate Two Strings

You are currently viewing Java Program to Concatenate Two Strings

Java program to concatenate two strings

import java.util.Scanner;

public class StringConcatenation 
{
	public static void main(String args[])
	{   // creating object of the string s1,s2.
		String s1,s2;
		Scanner sc=new Scanner(System.in);
		// enter both the string one by one.
		System.out.print("Enter First String : ");
		s1=sc.nextLine();
		 
		System.out.print("Enter Second String : ");
		s2=sc.nextLine();
		
		// here we print the whole string after concatenation.
		System.out.println("String After Concatenation : " +s1.concat(s2));
	}
}

Output

First run:
Enter First String : Include
Enter Second String : Help
String After Concatenation :IncludeHelp

Second run:
Enter First String : Java
Enter Second String : Programming
String After Concatenation : JavaProgramming

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply