I am trying to allow the user to remove a word from the string str. For example if they type "Hello my name is john", The output should be "Hello is john". How do i make this happen?
import java.util.*;
class WS7Q2{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.println("Please enter a sentence");
String str = in.nextLine();
int j;
String[] words = str.split(" ");
String firstTwo = words[0] + " " + words[1]; // first two words
String lastTwo = words[words.length - 2] + " " + words[words.length - 1];//last two words
System.out.println(str);
}
}