Advertisement
Monty374

Remove String

Oct 6th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. package removestring;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Removestring {
  6.  
  7. static Scanner scanner = new Scanner(System.in);
  8.  
  9. public static void main(String[] args) {
  10. System.out.println("Input Sentence: ");
  11. String input = scanner.nextLine();
  12. System.out.println("Input word to be removed: ");
  13. String section = scanner.nextLine();
  14.  
  15. if(!(input.indexOf(section) == -1)){
  16. System.out.println(input.substring(0, input.indexOf(section)) + input.substring(input.indexOf(section) + section.length()));
  17. } else {
  18. System.out.println("Word not found");
  19. }
  20. }
  21.  
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement