AJ Java Programs
Program 6:
Remove Duplicate Words From StringExample:
Input: blogger output: bloger
Syntax:
import java.io.*;
class RemoveDuplicateCharacter
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter any word : ");
String s = br.readLine();
int l = s.length();
char ch;
String ans="";
for(int i=0; i<l; i++)
{
ch = s.charAt(i);
if(ch!=' ')
ans = ans + ch;
s = s.replace(ch,' '); //Replacing all occurrence of the current character by a space
}
System.out.println("Word after removing duplicate characters : " + ans);
}
}
Tested Ok Program
If You Don't Understand anything or want any program please write your request in Comment Section
And Please Like The Post
Comments
Post a Comment