for the string "an example", i want to remove the dulipcate character from that string. and how do it remove the spaces between the words?
in the end i should get:
"anexmpl".
thanks.
Printable View
for the string "an example", i want to remove the dulipcate character from that string. and how do it remove the spaces between the words?
in the end i should get:
"anexmpl".
thanks.
removing spaces is as simple as
If noone else gets the other part before i get up tommarrow I will help you out but i gotta sleep now.Code:words = words.replaceAll(" ", "");
so how to remove duplicate character. i need that urgently.
thanks.
Ok, there are a few different ways this can be done, heres what I did:
Code:import java.util.*;
public class DublicateRemoval
{
public static void main (String[] args)
{
Scanner myInput = new Scanner(System.in);
String words = myInput.nextLine();
//removing spaces
words = words.replaceAll(" ", "");
//replace duplicates
String temp = "";
int position = 0;
while(position < words.length())
{
temp = words.substring(position + 1);
temp = temp.replaceAll(words.charAt(position) + "", "");
//System.out.println(temp);
//System.out.println(words.substring(0, position+1));
words = words.substring(0, position + 1) + temp;
position ++;
}
System.out.println(words);
}
}