RGAlex

O6. Replace Repeating Chars / Text Processing - Exercise

Mar 12th, 2021
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. package TextPlocessing.Exercise;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Scanner;
  6.  
  7. public class O6ReplaceRepeatingChars {
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner(System.in);
  10.         String input = scanner.nextLine();
  11.         List<Character> characterList = new ArrayList<>();
  12.  
  13.         for (char c : input.toCharArray() ) {
  14.             characterList.add(c);
  15.         }
  16.         for (int i = 1; i < characterList.size(); i++) {
  17.             if (characterList.get(i - 1) == characterList.get(i)) {
  18.                 characterList.remove(i);
  19.                 i--;
  20.             }
  21.         }
  22.         for (Character a : characterList) {
  23.             System.out.print(a);
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment