Przeglądaj źródła

arrAnalyz 11 - 11

tictactoe 21 - 21
waveGener 10 - 10
Total     41 - 108
Nick Satinover 6 lat temu
rodzic
commit
3e1764d416

+ 38
- 1
src/main/java/rocks/zipcode/io/quiz3/arrays/WaveGenerator.java Wyświetl plik

@@ -1,10 +1,47 @@
1 1
 package rocks.zipcode.io.quiz3.arrays;
2 2
 
3
+import java.lang.reflect.Array;
4
+import java.util.ArrayList;
5
+import java.util.Arrays;
6
+
3 7
 /**
4 8
  * @author leon on 09/12/2018.
5 9
  */
6 10
 public class WaveGenerator {
7 11
     public static String[] wave(String str) {
8
-        return null;
12
+
13
+
14
+        String[] waveArr = new String[str.length()];
15
+        char[] charArr = str.toLowerCase().toCharArray();
16
+
17
+        for (int i = 0; i < waveArr.length; i++) {
18
+
19
+            StringBuilder builder = new StringBuilder();
20
+
21
+            for (int j = 0; j < waveArr.length; j++) {
22
+                if (charArr[i] >= 97 && charArr[i] <= 122) {
23
+
24
+                    if (j == i && charArr[j] >= 97 && charArr[j] <= 122) {
25
+                        String upperLetter = String.valueOf(charArr[j]).toUpperCase();
26
+                        builder.append(upperLetter);
27
+                    } else {
28
+                        builder.append(charArr[j]);
29
+                    }
30
+
31
+                }
32
+            }
33
+            waveArr[i] = builder.toString();
34
+        }
35
+
36
+
37
+        ArrayList<String> waveList = new ArrayList<>();
38
+
39
+        for (String s: waveArr) {
40
+            if(s.length() != 0){
41
+                waveList.add(s);
42
+            }
43
+        }
44
+
45
+        return waveList.toArray(new String[waveList.size()]);
9 46
     }
10 47
 }