Didart

Substring

Nov 10th, 2021
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.47 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Substring {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         String toRemove = scanner.nextLine();
  8.         String text = scanner.nextLine();
  9.  
  10.         int index = text.indexOf(toRemove);  //-1
  11.  
  12.         while (index != -1) {
  13.             text = text.replace(toRemove, "");
  14.             index = text.indexOf(toRemove);
  15.         }
  16.         System.out.println(text);
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment