|
@@ -5,6 +5,23 @@ package rocks.zipcode.io.quiz3.arrays;
|
5
|
5
|
*/
|
6
|
6
|
public class WaveGenerator {
|
7
|
7
|
public static String[] wave(String str) {
|
8
|
|
- return null;
|
|
8
|
+ String[] result = new String[countAlphas(str)];
|
|
9
|
+ String str2 = str.toLowerCase();
|
|
10
|
+ int idx = 0;
|
|
11
|
+ for (int i=0; i<str.length(); i++){
|
|
12
|
+ if (Character.isLetter(str.charAt(i))) {
|
|
13
|
+ result[idx] = str2.substring(0, i) + Character.toUpperCase(str2.charAt(i)) + str2.substring(i + 1);
|
|
14
|
+ idx++;
|
|
15
|
+ }
|
|
16
|
+ }
|
|
17
|
+ return result;
|
|
18
|
+ }
|
|
19
|
+
|
|
20
|
+ private static int countAlphas(String str){
|
|
21
|
+ int count = 0;
|
|
22
|
+ for (int i=0; i<str.length(); i++)
|
|
23
|
+ if (Character.isLetter(str.charAt(i)))
|
|
24
|
+ count++;
|
|
25
|
+ return count;
|
9
|
26
|
}
|
10
|
27
|
}
|