Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ReplaceRepeatingChars {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String letter = scanner.nextLine().trim();
- StringBuilder sequence = new StringBuilder();
- if (letter == null || letter.length() == 0) {
- return;
- }
- char previousSymbol = letter.charAt(0);
- sequence.append(previousSymbol);
- for (int index = 1; index < letter.length(); index++) {
- char symbol = letter.charAt(index);
- if (symbol != previousSymbol) {
- sequence.append(symbol);
- previousSymbol = symbol;
- }
- }
- System.out.println(sequence);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment