blob: 446ff9dc966aa812edfb7cd008673b339ab5e994 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
import java.util.*;
public class MergeStrings {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter first string");
String first = scanner.nextLine();
System.out.println("Enter second string");
String second = scanner.nextLine();
StringBuilder sb = new StringBuilder();
int i = 0;
while (i < first.length() && i < second.length()) {
sb.append(first.charAt(i));
sb.append(second.charAt(i));
i++;
}
if (first.length() > second.length()) {
sb.append(first.substring(i));
} else if (second.length() > first.length()) {
sb.append(second.substring(i));
}
System.out.println(sb);
}
}
|