Answers for "Write a program to input a word from the user and remove the consecutive repeated characters by replacing the sequence of repeated characters by its single occurrence."

0

Write a program to input a word from the user and remove the consecutive repeated characters by replacing the sequence of repeated characters by its single occurrence.

//java program to input a word from the user and remove the consecutive repeated characters by replacing the sequence of repeated characters by its single occurrence
import java.util.*;
class Remove_Rep_Char
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter any word: "); 
        String s = sc.nextLine();
        s = s + " "; 
        int l=s.length(); 
        String ans=""; 
        char ch1,ch2;
        for(int i=0; i<l-1; i++)
        {
            ch1=s.charAt(i);
            ch2=s.charAt(i+1); 
            if(ch1!=ch2)
            {                   
            ans = ans + ch1;
            }
        }
        System.out.println("Word after removing repeated characters = "+ans); 
    }
}
Posted by: Guest on July-14-2020
0

Write a program to input a word from the user and remove the consecutive repeated characters by replacing the sequence of repeated characters by its single occurrence.

creeple
Posted by: Guest on August-04-2021

Code answers related to "Write a program to input a word from the user and remove the consecutive repeated characters by replacing the sequence of repeated characters by its single occurrence."

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language