Java program to concatenate two strings without using library function

In this java program, we are going to learn how to concatenate two strings without using library function?
Submitted by Preeti Jain, on March 13, 2018

First way is to write a program with the help of library function (concat) in java, read here: Java program to concatenate two strings

Second way is to write a program without the help of library function means we can make a program manually or our programming logic there is no need to use any readymade function.

Program to concatenate two strings without using library function in java

import java.util.Scanner;

class ConcatenateString{
	public static void main(String[] args){
		/* create Scanner class object */
		Scanner sc = new Scanner(System.in);
		
		/* Display message for user to take first 
		string input from keyboard */
		System.out.println("Enter First String :");
		String firstStr = sc.next();
		
		/* Display message for user to take first 
		string input from keyboard */
		System.out.println("Enter Second String :");
		String secondStr = sc.next();
		
		/* Display message for displaying result */
		System.out.println("Result after concatenation:");
		
		/* '+' operator concatenate string */
		System.out.println(firstStr+ " " + secondStr);
	}
}

Output

D:\Java Articles>java ConcatenateString
Enter First String :
preeti
Enter Second String :
jain
Result after concatenation:
preeti jain

Java String Programs »



Related Programs



Comments and Discussions!

Load comments ↻





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