Concatenate Two Strings
This program concatenates two strings.
Problem Statement
Write a Java program to concatenate two strings.
Source Code
| 1 | public class StringConcatenation { |
| 2 | public static void main(String[] args) { |
| 3 | System.out.println("Eduinq String Concatenation"); |
| 4 | String s1="Hello", s2="World"; |
| 5 | String result=s1+" "+s2; |
| 6 | System.out.println("Concatenated string: "+result); |
| 7 | } |
| 8 | } |
Program Output
Eduinq String Concatenation Concatenated string: Hello World
Explanation
The strings s1 and s2 are initialized separately, and the + operator joins them together with a space in between, demonstrating string concatenation.