File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ package easy ;
2+
3+ /**
4+ * Have the function StringMerge(str) read the str parameter being passed
5+ * which will contain a large string of alphanumeric characters with
6+ * a single asterisk character splitting the string evenly into two separate strings.
7+ * Your goal is to return a new string by pairing up the characters
8+ * in the corresponding locations in both strings.
9+ * For example: if str is "abc1*kyoo" then your program should return the string akbyco1o
10+ * because a pairs with k, b pairs with y, etc.
11+ * The string will always split evenly with the asterisk in the center.
12+ */
13+ public class StringMerge {
14+
15+ /**
16+ * String Merge function.
17+ *
18+ * @param str input string
19+ * @return a new string with paired up characters
20+ */
21+ public static String stringMerge (String str ) {
22+ StringBuilder output = new StringBuilder ();
23+ String [] strArr = str .trim ().split ("\\ *" );
24+ String str1 = strArr [0 ];
25+ String str2 = strArr [1 ];
26+ for (int i = 0 ; i < str1 .length (); i ++) {
27+ output .append (str1 .charAt (i )).append (str2 .charAt (i ));
28+ }
29+ return output .toString ();
30+ }
31+
32+ /**
33+ * Entry point.
34+ *
35+ * @param args command line arguments
36+ */
37+ public static void main (String [] args ) {
38+ String result = stringMerge ("123hg*aaabb" );
39+ System .out .println (result );
40+ }
41+
42+ }
You can’t perform that action at this time.
0 commit comments