Last active
April 10, 2018 14:25
-
-
Save DonKeyHot1/677ab43e107886425a056c3fdd5d2cd4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String str1 = 'testqtest.' //Тут можете ввод с клавиатуры сделать | |
char[] chars = str1.getChars() //Получаем массив символов | |
String result = '' //результат в начале - пустая строка | |
for (int i = 0; i < chars.length; i++) | |
{ | |
char currentSymbol = chars[i] // Получаем текущий символ | |
if (currentSymbol == 'q') //Если текущий символ - это q | |
{ | |
if ((i + 1) % 2 == 0) //Если текущий символ - четный | |
{ | |
result += 'qq' //В результат добавляем двойное q | |
} | |
//Если текущий символ - нечетный - то ничего не делаем | |
} | |
else // иначе просто добавим в результат текущий символ | |
{ | |
result += currentSymbol | |
} | |
} | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment