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