Demetrius Murray 6 years ago
parent
commit
5edc69ad37
1 changed files with 18 additions and 1 deletions
  1. 18
    1
      src/main/java/rocks/zipcode/io/quiz3/arrays/WaveGenerator.java

+ 18
- 1
src/main/java/rocks/zipcode/io/quiz3/arrays/WaveGenerator.java View File

5
  */
5
  */
6
 public class WaveGenerator {
6
 public class WaveGenerator {
7
     public static String[] wave(String str) {
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
 }