Java String Programs
Solution

Write a program to remove duplicate consecutive character or elements.
Input:"commppuutteerr"		Output:"computer"


 
import java.util.*;
class duplicatechar
{
    public static void main()
    {
       String s="commppuutteerr"; 
        
        String n=" ";
        char pre=' ';
        for(int i=0;i<s.length();i++)
        {
		
         if(pre!=s.charAt(i))
         {
//If my previous character and current character is not same then it will add the character in n string.
          n=n+s.charAt(i);
         }
        pre=s.charAt(i);//passing the current character in pre charecter.  
        }
        System.out.println(n);  
    }
       
}