Menu
Topics Index
...
`

Remove preoccured characters from the sentence remove extra spaces


If you need explanation Read this topic

If you need Answer Take test on this topic

Write a program to remove the preoccured characters from the given sentence. If the all the letters of word get removed, then do not include the space before the word. Do not use the methods replace or replaceAll.

Input (String) Output (String)
Hello How are you Helo w ar yu
I am a good boy I am god by
Sun rises in the east Sun rie th a
Good is good so long as it is good God is ln a t
Indians love cricket Indas love crkt
Learn Java with Merit Campus Learn Jv with M Cpus



class RemovePreoccuredCharactersAdvanced
{
    public static void main(String s[])
    {
        String sentence = "Sun rises in the east";
        System.out.println("After removing pre occured characters : " + removePreoccuredCharacters(sentence));

    }


    public static String removePreoccuredCharacters(String sentence) {
    }

}
Topic: toLowerCase() And toUpperCase() Methods In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

here we need to find the unique string from the given string so we need to remove the duplicate chars ignoring the cases(lower r upper)
* take an temp String variable and add the 1st char to it
* start for loop starts at 1 and till it reaches the end of the String
* if the charAt(i) is space(' ') than directly add to the temp
* else check if the charAt(i) already contains in the temp than dont add other wise add it,here checj for the both cases
* after coming out of the loop return the String

Posted by Uday Kumar    2015-03-05 06:23:22


here we havr to removed the preoccured character in a given string..... here we go with the logic.. ->>   1)  firstly take an temporary string variable temp="   "...........2) Then take a loop and traverse through every character of input.... take a=0 to input.length {..... ch=input.charAt(a)...........4)now if ch=' ' then add it directly to temp......... 5) else.  {    flag=0.. ....6)now take anothrr loop to chek whthr ch is present in temp or not.... take b=0 to temp.length...... if(ch==temp.charAt(b)) then increment flag by one .....exit this loop...} ....7)......hrre chek if flag=0 then add ch to temp.... exit else... exit main loop.... now temp variabl contains required result

Posted by Asma Mujtaba Khan    2015-03-05 06:51:45


This dose is now closed and the winners are Uday Kumar,  for 'First Correct Comment'. The 'lucky liker' is Sai Ram. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Prem Sai    2015-03-06 01:55:27


© meritcampus 2019

All Rights Reserved.

Open In App