File tree Expand file tree Collapse file tree 2 files changed +8
-11
lines changed
src/main/java/by/andd3dfx/string Expand file tree Collapse file tree 2 files changed +8
-11
lines changed Original file line number Diff line number Diff line change @@ -258,8 +258,8 @@ they contain enough code which describes implementation in a natural way.
258
258
| Ревью кода из интервью 7 (LIVE) | [ Youtube] ( https://youtu.be/qvyJ0rxXcg0 ) | - |
259
259
| Как скачать видео с Boosty | [ Youtube] ( https://youtu.be/b3ox1_xEx4U ) | [ Boosty] ( https://boosty.to/andd3dfx ) |
260
260
| Прохождение теста подтверждения практического навыка "средний" по Java на hh.ru | [ Youtube] ( https://youtu.be/ja4nLzZSj3s ) | - |
261
- | Прохождение теста подтверждения практического навыка "продвинутый" по Java на hh.ru | [ Youtube] ( https://youtu.be/ce3g0nIJl24 ) | - |
262
261
| Декодирование шифра Цезаря | [ Youtube] ( https://youtu.be/pjQ9sYo5bVE ) | [ Code] ( src/main/java/by/andd3dfx/string/CaesarCipher.java ) |
262
+ | Прохождение теста подтверждения практического навыка "продвинутый" по Java на hh.ru | [ Youtube] ( https://youtu.be/ce3g0nIJl24 ) | - |
263
263
264
264
## Materials & notes
265
265
Original file line number Diff line number Diff line change @@ -45,23 +45,20 @@ public class CaesarCipher {
45
45
private static final String ALPHABET = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя" ;
46
46
47
47
public String encode (String text , int shift ) {
48
- return encodeWordWithSpacesSupport (text , shift );
48
+ return encodeInner (text , shift );
49
49
}
50
50
51
51
public String decode (String text , int shift ) {
52
- return encodeWordWithSpacesSupport (text , -shift );
52
+ return encodeInner (text , -shift );
53
53
}
54
54
55
- private String encodeWordWithSpacesSupport (String text , int shift ) {
56
- var words = text .split (" " );
57
- return Arrays .stream (words )
58
- .map (word -> encodeWord (word , shift ))
59
- .collect (Collectors .joining (" " ));
60
- }
61
-
62
- private String encodeWord (String word , int shift ) {
55
+ private String encodeInner (String word , int shift ) {
63
56
var chars = word .toCharArray ();
64
57
for (var i = 0 ; i < chars .length ; i ++) {
58
+ if (chars [i ] == ' ' ) {
59
+ continue ;
60
+ }
61
+
65
62
var index = ALPHABET .indexOf (chars [i ]) + shift ;
66
63
while (index < 0 ) {
67
64
index += ALPHABET .length ();
You can’t perform that action at this time.
0 commit comments