-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEliminate.java
37 lines (37 loc) · 914 Bytes
/
Eliminate.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//Removing a substring from a string
import java.util.*;
class Eliminate{
String str;
Eliminate(){
str="";
}
Eliminate(String s){
str=s;
}
void remove(String ss){
String m="";int c=0;
int l=ss.length();
int i;
for(i=0;i<=str.length()-l;i++){
if(str.substring(i,i+l).equals(ss)){
c++;
i+=l;
m+=str.charAt(i);
}
else
m+=str.charAt(i);
}
m+=str.substring(i);
if(c==0)
System.out.println("Not found");
str=m;
}
void print(){
System.out.println("Original sentence="+str);
remove(new Scanner(System.in).nextLine());
System.out.println("New sentence="+str);
}
public static void main(String args[]){
new Eliminate(new Scanner(System.in).nextLine()).print();
}
}