String Question 12
Question 22. Write a Program to merge two strings.
Program
class Solution { String merge(String S1, String S2) { int n1 = S1.length(); int n2 = S2.length(); StringBuilder str = new StringBuilder(); int length= Math.max(n1,n2); for(int i=0;i<length;i++){ if(i<n1){ str.append(S1.charAt(i)); } if(i<n2){ str.append(S2.charAt(i)); } } return str.toString(); } } |