deyanmalinov

06. Replace Repeating Chars

Mar 25th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.51 KB | None | 0 0
  1. package DPM;
  2.  
  3. import java.util.*;
  4.  
  5. public class Main {
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.         String text = scan.nextLine();
  9.         String res ="";
  10.         char ch = text.charAt(0);
  11.         res += ch;
  12.         for (int i = 0; i < text.length(); i++) {
  13.             char symbol = text.charAt(i);
  14.             if (ch != symbol){
  15.                 ch=symbol;
  16.                 res +=ch;
  17.             }
  18.         }
  19.         System.out.println(res);
  20.     }
  21. }
Add Comment
Please, Sign In to add comment