Page 251 - computer science (868) class 11
P. 251
}
}
void display()
{
System.out.println("Original word: "+word);
System.out.println("Sorted word: "+sortwd);
}
public static void main()
{
convert ob= new convert();
ob.input();
ob.sortword();
ob.display();
}
}
5. Create a class Remove_Duplicates to remove duplicate characters from the given word. For example:
Sample Input: Applications
Sample Output: Aplictons
Class name : Remove_Duplicates
Data Members
String wd : To input the word
tempwd : To hold the value of "wd" variable
Member Methods
Remove_Duplicates(String ts) : parameterized constructor
void dup_rev() : removes the duplicate characters from the word
void display() : prints both the original word and the new word
Ans. import java.util.*;
class Remove_Duplicates
{
String wd,tempwd;
Remove_Duplicates(String ts)
{
wd=ts;
tempwd=wd;
}
void dup_rev()
{
int l=wd.length();
int c, i;
String s1="";
for( i=0; i<(l-1); i++)
{
s1=wd.substring(0,i+1);
c=0;
for(int j=i+1; j<l; j++)
{
if(wd.charAt(i)==wd.charAt(j))
{
c++;
continue;
}
else
s1=s1+wd.charAt(j);
}
wd=s1;
249
Strings 249

