Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package stringProcessing;
- import java.util.Scanner;
- public class replaceReapeatingChar {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- StringBuilder text = new StringBuilder(scanner.nextLine());
- StringBuilder result = new StringBuilder();
- for (int i = 0; i < text.length() ; i++) {
- char symbolOne = text.charAt(i);
- result.append(symbolOne);
- if(checkIfiIsWithingRange(i,text.length())) {
- while (symbolOne == text.charAt(i + 1)) {
- i++;
- if(!checkIfiIsWithingRange(i,text.length())){
- break;
- }
- }
- }else{
- break;
- }
- }
- System.out.println(result.toString());
- }
- public static boolean checkIfiIsWithingRange(int i,int lengthOfString){
- boolean in = true;
- if (i == lengthOfString - 1){
- in = false;
- }
- return in;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement