Java Programs

Java Practice

Java program to concatenate two strings

In this java program, we are going to learn how to concatenate two strings? Here, we have two strings which will be entered through the user and we will concatenate them.
Submitted by IncludeHelp, on November 19, 2017


String 1: "Include"
String 2: "Help"

Final string after concatenating: "IncludeHelp"

Program to concatenate two strings in java

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 : ");
		System.out.print("Enter Second String : ");
		// here we print the whole string after concatenation.
		System.out.println("String After Concatenation : " +s1.concat(s2));


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

Java String Programs »

Related Programs

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.