Java Program

Object:-Write a Program in java to concatenate two string.

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

Enter First String :
Rohit

Enter Second String :
Sharma

Result after concatenation:
Rohit Sharma
 

Explanation

In this program we have concatenate two string 








You may also like: