Skip to content

Instantly share code, notes, and snippets.

@DonKeyHot1
Last active April 10, 2018 14:25
Show Gist options
  • Save DonKeyHot1/677ab43e107886425a056c3fdd5d2cd4 to your computer and use it in GitHub Desktop.
Save DonKeyHot1/677ab43e107886425a056c3fdd5d2cd4 to your computer and use it in GitHub Desktop.
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