Advertisement
meteor4o

JF-TextProcessing-Exercise-06.ReplaceRepeatingChars

Jul 20th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.52 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class ReplaceRepeatingChars {
  6.     public static void main(String[] args) {
  7.         Scanner sc = new Scanner(System.in);
  8.  
  9.         String[] text = sc.nextLine().split("");
  10.  
  11.         StringBuilder sb = new StringBuilder();
  12.         sb.append(text[0]);
  13.         for (int i = 1; i < text.length; i++) {
  14.  
  15.             if (!text[i].equals(text[i-1])) {
  16.                 sb.append(text[i]);
  17.             }
  18.         }
  19.         System.out.println(sb.toString());
  20.  
  21.  
  22.  
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement