Here it is:
the user enters string and then then they enter a word from the sentnce they just entered in. then the program is supposed to take out the word they entered and then display the new sentence..

How to do this ????????
really need help PLEASE... :(

this is what i have so far...

import java.util.Scanner;
public class RemoveString {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input=new Scanner(System.in);   

        String sent;
        String string;
        String part;

        System.out.println("Enter a sentence:");
        System.out.println("Enter a string:");


Edited by Nick Evan: Fixed formatting

8 Years
Discussion Span
Last Post by gunjannigam

This case can have 2 cases.
1) Delete all the occurence of given word
2)Delete only a given occurence(mostly first) of given word

You have to split the input sentence using String.split() method. It will result into a array of Sring, containing all your words. Now compare all your words with the given input word. If a match is not there append the word into a StringBuilder along with a space. This will remove all the occuerence. If you want to delete a particular instance. Count the no of instance and break from the loop accordingly

Edited by Nick Evan: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.