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.
258258| Ревью кода из интервью 7 (LIVE) | [ Youtube] ( https://youtu.be/qvyJ0rxXcg0 ) | - |
259259| Как скачать видео с Boosty | [ Youtube] ( https://youtu.be/b3ox1_xEx4U ) | [ Boosty] ( https://boosty.to/andd3dfx ) |
260260| Прохождение теста подтверждения практического навыка "средний" по Java на hh.ru | [ Youtube] ( https://youtu.be/ja4nLzZSj3s ) | - |
261- | Прохождение теста подтверждения практического навыка "продвинутый" по Java на hh.ru | [ Youtube] ( https://youtu.be/ce3g0nIJl24 ) | - |
262261| Декодирование шифра Цезаря | [ Youtube] ( https://youtu.be/pjQ9sYo5bVE ) | [ Code] ( src/main/java/by/andd3dfx/string/CaesarCipher.java ) |
262+ | Прохождение теста подтверждения практического навыка "продвинутый" по Java на hh.ru | [ Youtube] ( https://youtu.be/ce3g0nIJl24 ) | - |
263263
264264## Materials & notes
265265
Original file line number Diff line number Diff line change @@ -45,23 +45,20 @@ public class CaesarCipher {
4545 private static final String ALPHABET = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя" ;
4646
4747 public String encode (String text , int shift ) {
48- return encodeWordWithSpacesSupport (text , shift );
48+ return encodeInner (text , shift );
4949 }
5050
5151 public String decode (String text , int shift ) {
52- return encodeWordWithSpacesSupport (text , -shift );
52+ return encodeInner (text , -shift );
5353 }
5454
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 ) {
6356 var chars = word .toCharArray ();
6457 for (var i = 0 ; i < chars .length ; i ++) {
58+ if (chars [i ] == ' ' ) {
59+ continue ;
60+ }
61+
6562 var index = ALPHABET .indexOf (chars [i ]) + shift ;
6663 while (index < 0 ) {
6764 index += ALPHABET .length ();
You can’t perform that action at this time.
0 commit comments