Java String Programs Solution
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);
}
}
