We can use if condition to check consecutive letters are the same or not. Example: if(word.charAt(j) == word.charAt(j + 1))